[英]Error: The top-level-await experiment is not enabled, but loader is already installed
This is the full error:这是完整的错误:
ERROR in ./src/index.js
Module parse failed: The top-level-await experiment is not enabled (set experiments.topLevelAwait: true to enabled it)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
Error: The top-level-await experiment is not enabled (set experiments.topLevelAwait: true to enabled it)
but topLevelAwait is already enabled in webpack.config.js.但是在 webpack.config.js 中已经启用了 topLevelAwait。
webpack.config.js: webpack.config.js:
const path = require('path');
module.exports = {
// The entry point file described above
entry: './src/index.js',
// The location of the build folder described above
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
module: {
rules: [{
test: '/\.js|\.jsx$/',
use: 'raw-loader' }],
},
// Optional and for development only. This provides the ability to
// map the built code back to the original source format when debugging.
devtool: 'eval-source-map',
experiments: {
topLevelAwait: true,
},
};
js: js:
import { initializeApp } from "firebase/app";
// import { getAnalytics } from "firebase/analytics";
import { getFirestore, collection, getDocs } from "firebase/firestore";
const firebaseApp = initializeApp({
apiKey: "AIzaSyDLl4mlsDgKXzYqu7BtWj60Gne3ybwxEXU",
authDomain: "tutorbuddy-a5411.firebaseapp.com",
projectId: "tutorbuddy-a5411",
storageBucket: "tutorbuddy-a5411.appspot.com",
messagingSenderId: "402150617426",
appId: "1:402150617426:web:eaab24a4375b5c543cca8b",
measurementId: "G-B2KF86YVXC"
});
const db = getFirestore(firebaseApp);
const todosCol = collection(db, 'todos');
const snapshot = await getDocs(todosCol);
// const analytics = getAnalytics(app);
Probably a really simple answer, but I've been at this for a while haha any help is really appreciated!!可能是一个非常简单的答案,但我已经有一段时间了哈哈任何帮助都非常感谢!
Had the same error message when trying to addoc, it had already created the webpack config file and it kept failing.尝试添加时出现相同的错误消息,它已经创建了 webpack 配置文件,并且一直失败。 I solved it by just wrapping with an async function as follows: enter image description here
我通过使用异步 function 包装解决了它,如下所示:在此处输入图像描述
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.