英文:
Does the top-level-await error mean Webpack is already installed?
问题
I'm getting the error
'模块解析失败:未启用顶级等待实验(设置experiments.topLevelAwait: true以启用它)'
After some research, I created a 'webpack.config.js' file in the same location as my 'package.json' file. Here is the content
module.exports = {
experiments: {
topLevelAwait: true
}
};
This had no effect. I still get the error.
Do I need to explicitly install Webpack and then create the config file? That seems odd since the original error itself implies Webpack is already there.
Here are the dependencies from my 'package.json' file. Webpack isn't there.
"dependencies": {
"@aws-amplify/ui-react": "^4.6.2",
"@nextui-org/react": "^1.0.0-beta.12",
"aws-amplify": "^5.2.1",
"next": "^13.4.2",
"react": "18.2.0",
"react-dom": "18.2.0"
}
- 我是否需要安装Webpack?
- 或者,如果我不需要安装它,我需要更改'webpack.config.js'文件的哪些内容才能使其正常工作?
英文:
I'm getting the error
Module parse failed: The top-level-await experiment is not enabled (set experiments.topLevelAwait: true to enabled it)
After some research, I created a webpack.config.js
file in the same location as my package.json
file. Here is the content
module.exports = {
experiments: {
topLevelAwait: true
}
};
This had no effect. I still get the error.
Do I need to explicitly install Webpack and then create the config file? That seems odd since the original error itself implies Webpack is already there.
Here are the dependencies from my package.json
file. Webpack isn't there.
"dependencies": {
"@aws-amplify/ui-react": "^4.6.2",
"@nextui-org/react": "^1.0.0-beta.12",
"aws-amplify": "^5.2.1",
"next": "^13.4.2",
"react": "18.2.0",
"react-dom": "18.2.0"
}
- Do I need to install Webpack anyway?
- Or, if I don't need to install it, what do I need to change about the
webpack.config.js
file to get this working?
答案1
得分: 1
NextJS内部嵌入了Webpack,因此已安装Webpack。
此外,启用顶级等待的方法是在 next.config.js
文件中添加注释,如下所示:
module.exports = {
webpack: (config) => {
// this will override the experiments
config.experiments = {...config.experiments, topLevelAwait: true};
// this will just update topLevelAwait property of config.experiments
// config.experiments.topLevelAwait = true
return config;
},
};
英文:
It turns out NextJS has Webpack embedded in it. Therefore Webpack is installed.
Also, the way to enable top-level-await is to annotate the next.config.js
file like this:
module.exports = {
webpack: (config) => {
// this will override the experiments
config.experiments = {...config.experiments, topLevelAwait: true};
// this will just update topLevelAwait property of config.experiments
// config.experiments.topLevelAwait = true
return config;
},
};
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论