我正在正确导入一个 Node 模块,但遇到一个问题,我正在导入的 Node 模块是用 es6 编写的,而 babel 无法转换它。
在基类头中:
import foo from 'bar/lib/foo';
在 Node 模块中的 foo.js 中:
import Debug from 'debug';
export default class foo from bar {
...
...
...
}
错误信息:
import Debug from 'debug';
^^^^^^
SyntaxError: Unexpected token import
如您所见,它能够找到文件 foo.js 但它没有在 es6 中运行 Node 模块。我怎样才能让 Babel 转译基础代码以及它尝试导入的 Node 模块?
最佳答案
你有包含此内容的 .babelrc 文件吗?
{
"presets": ["es2015"],
"plugins": []
}
您可以在此处查看示例:https://github.com/Talento90/ima-up
关于node.js - 巴别塔 ES6 : Import node modules that need to be transpiled in ES6 as well,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35609620/