这是完整的错误:
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)
但是webpack.config.js中已经启用了topLevelAwait。
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:
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);
可能是一个非常简单的答案,但我已经在这一段时间哈哈任何帮助是真的很感激!!
1条答案
按热度按时间lyfkaqu11#
在尝试addoc时出现同样的错误信息,它已经创建了webpack配置文件,并且一直失败。我通过使用一个异步函数来解决这个问题,如下所示: