问题描述
我正在尝试建立一个节点项目,以便可以使用常见的导入/导出语法,并且为了兼容,请使用babeljs将import
和export
语句转换为{{1} } s。
但是当我尝试使用babel进行转译时,我没有看到任何更改,也不知道为什么。
这是我的require
babel.config.js
我有一堆使用// babel.config.js
module.exports = {
// I thought this was what I would need to add for making the changes,based on the docs
plugins: ["@babel/plugin-transform-modules-commonjs"],// env takes care of the majority of changes I might need to convert code to make
// easy to run on a wider range of machines
presets: [
[
"@babel/preset-env",{
targets: {
// target an older version where I kNow there is no ESM support
node: "10"
}
}
]
],// this was in the docs too - I'm not sure if I need it TBH
sourceType: "module"
}
和import/export
的代码在一个目录中,我想将它们转换并放入另一个目录async/await
。
这是我正在使用的命令:
lib
我的package.json文件也在线,那里没有什么太深奥的。我试图忠实地遵循文档。
我希望在代码中看到一些变化,以在lib中用require代替导入/导出调用,但是没有乐趣。
我在这里做错了什么?我在6到7个月前参与了一个相关项目,我正在像这样使用babel,它确实为我做出了改变。
您可以看到branch with the problem code on github,package.json和here's the source code for other project mentioned where it is working。
SO评论员,请保持温柔-我正在竭尽全力,我确实是。
解决方法
似乎您正在使用"babel-cli": "^6.26.0"
而不是"@babel/cli": "^7.11.6"
来解决此问题。