gpt4 book ai didi

javascript - 在 Babeljs 配置中使用原生 ECMAScript 模块

转载 作者:行者123 更新时间:2023-12-01 15:26:55 27 4
gpt4 key购买 nike

我对将 babel 配置与原生 ECMAScript 模块和 "type": "module" 一起使用感到非常非常困惑。设置在 package.json .据我了解 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 .

这是预期的,因为上述文档指出“ native ECMAScript 模块是异步的”。唉,用 async 喷洒上述配置/ await不能解决问题。我正在运行 babel通过 parcel - 这是 parcel 的问题吗? ?我误解了文档吗?如果有人能为我澄清一下,我真的很感激。

最佳答案

我遇到了类似的问题,阅读 Babel 站点后,我得出结论,无论使用您的 babel 配置,都不会异步调用它。就我而言,它是开玩笑的 26 岁。
我通过将配置更改为 json 文件解决了这个问题 - babel.config.json .
其他人已将他们的配置文件更改为 commonjs 文件 - babel.config.cjs ,那么您需要将配置文件更改为 commonjs,即使用 module.exports = {rest of your config}

关于javascript - 在 Babeljs 配置中使用原生 ECMAScript 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61257559/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com