面对下面的构建问题:
Module parse failed: The top-level-await experiment is not enabled (set experiments.topLevelAwait: true to enabled it)
File was processed with these loaders:
* ./node_modules/babel-loader/lib/index.js
* ./node_modules/source-map-loader/dist/cjs.js
You may need an additional loader to handle the result of these loaders.
Error: The top-level-await experiment is not enabled (set experiments.topLevelAwait: true to enabled it)
有什么解决办法吗?
发布于 2022-06-22 10:58:28
在导出带有异步的模块时,我得到了这个错误。只需将其添加到module.exports文件中的webpack.config.js对象即可。
experiments: {
topLevelAwait: true
}
你也可以阅读Webpack文档中的实验选项。https://webpack.js.org/configuration/experiments/
发布于 2022-10-17 10:11:32
您可以在webpack配置中启用它。
如果您使用npx create-react-app my-app
创建了您的react应用程序,您必须安装克拉科来覆盖您的webpack配置。
安装后,在您的topLevelAwait中将craco.config.js设置为true:
module.exports = {
webpack: {
configure: {
experiments: {
topLevelAwait: true,
},
},
},
};
运行npm start
,错误就消失了。
发布于 2022-11-07 15:16:11
Symfony
对于任何试图将其添加到symfony生成的webpack.config.js中的人,您可以使用以下语法:
// Default config above...
const config = Encore.getWebpackConfig();
config.experiments = {
topLevelAwait: true,
}
module.exports = config;
https://stackoverflow.com/questions/72474803
复制相似问题