我对在原生ECMAScript模块中使用babel config以及在package.json
中设置"type": "module"
感到非常困惑。据我所知,Babel文档(here,在“支持的文件扩展名”下)应该是可能的。但是如果我尝试这样的配置:
const config = () => {
const presets = [
"@babel/preset-react",
[
"@babel/preset-env",
{
bugfixes: true,
useBuiltIns: "usage",
corejs: { version: "3.6", proposals: true },
},
],
];
const plugins = ["@babel/plugin-transform-runtime"];
return { presets, plugins };
};
export default config;
我得到了Error while loading config - You appear to be using a native ECMAScript module configuration file, which is only supported when running Babel asynchronously
。
正如上述文档所述,这是意料之中的,因为“本机ECMAScript模块是异步的”。遗憾的是,在上面的配置中使用async
/ await
并不能解决问题。我正在通过parcel
运行babel
-这是parcel
的问题吗?我误解文档了吗?如果有人能帮我澄清一下,我真的很感激。
发布于 2020-08-02 22:12:00
我也遇到过类似的问题,在阅读Babel站点时,我得出结论,无论使用您的babel配置的是什么,都不会异步调用它。在我的例子中,它是jest 26。
我通过将配置更改为json文件- babel.config.json
解决了这个问题。其他人已经将他们的配置文件更改为commonjs文件- babel.config.cjs
,那么您需要将您的配置文件更改为commonjs,即使用module.exports = {rest of your config}
https://stackoverflow.com/questions/61257559
复制相似问题