Node.js 在小节点项目上使用带有预设env的babel,无法将导入/导出语句转换为commonjs
我正在尝试设置一个节点项目,以便使用通用的导入/导出语法,并且为了兼容性,使用babeljs将Node.js 在小节点项目上使用带有预设env的babel,无法将导入/导出语句转换为commonjs,node.js,babeljs,commonjs,Node.js,Babeljs,Commonjs,我正在尝试设置一个节点项目,以便使用通用的导入/导出语法,并且为了兼容性,使用babeljs将import和export语句转换为requires 当我尝试使用babel进行传输时,我没有看到任何变化,也不知道为什么 这是我的babel.config.js // babel.config.js module.exports = { // I thought this was what I would need to add for making the changes, based on t
import
和export
语句转换为require
s
当我尝试使用babel进行传输时,我没有看到任何变化,也不知道为什么
这是我的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
下面是我正在使用的命令:
npx babel src --out-dir lib
我的package.json文件也在线,没有什么太深奥的东西。我试着忠实地遵循文档
我希望看到代码中的更改,用lib中的requires替换导入/导出调用,但没有乐趣
我做错了什么?6-7个月前我在一个相关的项目上工作,在那里我像这样使用babel,它确实为我做出了改变
您可以看到,以及
请温柔一点,各位评论者-我正在尽我最大的努力,我真的是。看起来你使用的是
“babel cli”:“^6.26.0”
而不是“@babel/cli”:“^7.11.6”
,应该可以解决这个问题