在小型节点项目上将babel与preset-env一起使用,无法将导入/导出语句转换为commonjs

问题描述

我正在尝试建立一个节点项目,以便可以使用常见的导入/导出语法,并且为了兼容,请使用babeljs将importexport语句转换为{{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 githubpackage.jsonhere's the source code for other project mentioned where it is working

SO评论员,请保持温柔-我正在竭尽全力,我确实是。

解决方法

似乎您正在使用"babel-cli": "^6.26.0"而不是"@babel/cli": "^7.11.6"来解决此问题。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...