我正在使用Babel编译我的JavaScript代码,并且为webpack(基础)和Node(覆盖)设置了单独的配置:
module.exports = {
presets: [
[
'@babel/env',
{
modules: false,
useBuiltIns: 'usage',
},
],
'@babel/react',
'@babel/flow',
],
overrides: [
{
include: ['src/scripts'],
presets: [
[
'@babel/env',
{
modules: 'commonjs',
useBuiltIns: 'usage',
targets: {
node: '6',
},
},
],
],
},
],
};
所以scripts
是我的Node代码,其余的是客户端(webpack)。我无法从任何其他文件夹中的模块导入scripts
文件夹内的任何内容。
如果我使用默认导出:
export default function fn() {}
并像这样导入它:
import fn from '../scripts/fn'
我看到此错误:
"export 'default' (imported as 'fn') was not found in '../scripts/fn'
如果我使用命名导出:
export function fn() {}
并像这样导入它:
import {fn} from '../scripts/fn'
我看到此错误:
"'../scripts/fn' does not contain an export named 'fn'.