简体   繁体   English

错误:未启用顶级等待实验,但已安装加载程序

[英]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.

相关问题 await 仅在异步函数和模块的顶层主体中有效 javascript 表示错误 - await is only valid in async functions and the top level bodies of modules javascript express error 我已经安装了firebase,错误依旧 - I already installed firebase and the error remains ERROR 'await' 表达式只允许在异步函数中和模块的顶层 - ERROR 'await' expressions are only allowed within async functions and at the top levels of modules GCP Vertex AI 已启用时“启用必要的 API” - GCP Vertex AI "Enable necessary APIs" when already enabled Firebase setDoc 导致 async/await 错误 - Firebase setDoc results in a async/await error 为什么我应该从 APIM 启用 OAuth,因为它已经使用 Microsoft Identity 平台安全 - Why should I enabled OAuth from APIM when it is already secure using Microsoft Identity platform 如何解决解析错误:意外的保留字“await” - How to resolve parsing error: Unexpected reserved word 'await' 将 Google Secret Manager 与 Firebase 函数和 Stripe(顶级)结合使用 - Using Google Secret Manager with Firebase Functions and Stripe (top level) AWS Spot 实例引导失败:package amazon-ssm-agent 已安装 - AWS Spot Instance bootstrap failed : package amazon-ssm-agent is already installed Django Google App Engine:502 错误网关,已安装 package 无法识别 - Django Google App Engine: 502 Bad Gateway, already installed package not recognized
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM