Firebase v9 and Nuxt 2.15.8 - SyntaxError: Cannot use import statement outside a module

Firebase v9 and Nuxt 2.15.8 - SyntaxError: Cannot use import statement outside a module

我正在迁移我的代码库以使用 firebase 版本 9 SDK,并且在我开始使用 v9 firestore 后开始出现此错误。我已经迁移了我的身份验证部分,并且效果很好。

我应该注意,这只发生在我静态生成我的网站 (npm run generate) 时,而不是在为 SSR (npm run build) 构建网站时。在开发过程中 (npm run dev) 我没有收到任何错误。对于必须生成的每个页面都会出现错误。它似乎引用了 messaging 模块,但我并没有在每个页面上使用 messaging。请参阅下面的错误示例:

 ERROR   /faqs

C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging\dist\index.sw.esm2017.js:1
import '@firebase/installations';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging-compat\dist\index.cjs.js:8:10)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\firebase\compat\messaging\dist\index.cjs.js:3:1)

nuxt.config.js

  plugins: [
    {src: '@/plugins/firebase',ssr: true },
  ]

plugins/firebase.js

import firebase from 'firebase/compat/app'
import 'firebase/compat/firestore'
import 'firebase/compat/storage'
import 'firebase/compat/messaging'
import 'firebase/compat/functions'


/*********************************** VERSION NINE ********************************** */
import { initializeApp, getApps } from "firebase/app";
import { getAuth } from "firebase/auth";
import { getAnalytics } from "firebase/analytics";
import { getFirestore } from "firebase/firestore"

const firebaseConfig = {
  apiKey: '',
  authDomain: '',
  databaseURL: '',
  projectId: '',
  storageBucket: '',
  messagingSenderId: '',
  appId: '',
  measurementId: ''
};

let firebaseApp;

const apps = getApps();
if (!apps.length) {
  firebaseApp = initializeApp(firebaseConfig);
} else {
  firebaseApp = apps[0];
}

const db = getFirestore(firebaseApp, {});
const auth = getAuth(firebaseApp);

if(process.browser){
  const analytics = getAnalytics(); //enable analytics
}
/*********************************** END OF VERSION NINE ********************************** */


/*********************************** VERSION EIGHT ********************************** */
if(!firebase.apps.length){
    const config = {
        apiKey: '',
        authDomain: '',
        databaseURL: '',
        projectId: '',
        storageBucket: '',
        messagingSenderId: '',
        appId: '',
        measurementId: ''
    };
    firebase.initializeApp(config);
    
}


const fireDb = firebase.firestore();
const fireStorage =firebase.storage();
const fireFunctions =firebase.functions();

let fireMessage = '';
if(process.browser){

  if(firebase.messaging.isSupported()){
   
    fireMessage= firebase.messaging();
  }
  else{
      
    console.warn('[WARNING] Firebase Cloud messaging not supported');
  }

}
/*********************************** END OF VERSION EIGHT ********************************** */

export{fireMessage, fireDb, fireStorage, fireFunctions, auth, db}

非常感谢您就此事提供指导。有一个tutorial I was following, the code is at this link。我成功克隆了该项目并 运行 npm run generate 所以我认为错误不是出在 firebase 上?我在下面附加了构建日志的剩余部分(它真的很长所以终端没有完整的日志):

i Full static generation activated
i Generating output directory: dist/
i Generating pages with full static mode

 ERROR   /about

C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging\dist\index.sw.esm2017.js:1
import '@firebase/installations';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging-compat\dist\index.cjs.js:8:10)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\firebase\compat\messaging\dist\index.cjs.js:3:1)


 ERROR   /faqs

C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging\dist\index.sw.esm2017.js:1
import '@firebase/installations';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging-compat\dist\index.cjs.js:8:10)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\firebase\compat\messaging\dist\index.cjs.js:3:1)


 ERROR   /legislation

C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging\dist\index.sw.esm2017.js:1
import '@firebase/installations';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging-compat\dist\index.cjs.js:8:10)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\firebase\compat\messaging\dist\index.cjs.js:3:1)


 ERROR   /references

C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging\dist\index.sw.esm2017.js:1
import '@firebase/installations';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging-compat\dist\index.cjs.js:8:10)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\firebase\compat\messaging\dist\index.cjs.js:3:1)


 ERROR   /vaccinationsites

C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging\dist\index.sw.esm2017.js:1
import '@firebase/installations';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging-compat\dist\index.cjs.js:8:10)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\firebase\compat\messaging\dist\index.cjs.js:3:1)


 ERROR   /admin/addevent

C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging\dist\index.sw.esm2017.js:1
import '@firebase/installations';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging-compat\dist\index.cjs.js:8:10)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\firebase\compat\messaging\dist\index.cjs.js:3:1)


 ERROR   /admin/addinitiative

C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging\dist\index.sw.esm2017.js:1
import '@firebase/installations';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging-compat\dist\index.cjs.js:8:10)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\firebase\compat\messaging\dist\index.cjs.js:3:1)


 ERROR   /admin/addsite

C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging\dist\index.sw.esm2017.js:1
import '@firebase/installations';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging-compat\dist\index.cjs.js:8:10)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\firebase\compat\messaging\dist\index.cjs.js:3:1)


 ERROR   /admin/dashboard

C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging\dist\index.sw.esm2017.js:1
import '@firebase/installations';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging-compat\dist\index.cjs.js:8:10)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\firebase\compat\messaging\dist\index.cjs.js:3:1)


 ERROR   /admin/deploy

C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging\dist\index.sw.esm2017.js:1
import '@firebase/installations';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging-compat\dist\index.cjs.js:8:10)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\firebase\compat\messaging\dist\index.cjs.js:3:1)


 ERROR   /admin/login

C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging\dist\index.sw.esm2017.js:1
import '@firebase/installations';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging-compat\dist\index.cjs.js:8:10)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\firebase\compat\messaging\dist\index.cjs.js:3:1)


 ERROR   /admin/notifications

C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging\dist\index.sw.esm2017.js:1
import '@firebase/installations';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging-compat\dist\index.cjs.js:8:10)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\firebase\compat\messaging\dist\index.cjs.js:3:1)


 ERROR   /admin/sitelocations

C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging\dist\index.sw.esm2017.js:1
import '@firebase/installations';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging-compat\dist\index.cjs.js:8:10)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\firebase\compat\messaging\dist\index.cjs.js:3:1)


 ERROR   /admin/updatestatistics

C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging\dist\index.sw.esm2017.js:1
import '@firebase/installations';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging-compat\dist\index.cjs.js:8:10)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\firebase\compat\messaging\dist\index.cjs.js:3:1)


 ERROR   /

C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging\dist\index.sw.esm2017.js:1
import '@firebase/installations';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\@firebase\messaging-compat\dist\index.cjs.js:8:10)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)    
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)     
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\covid19-tt\node_modules\firebase\compat\messaging\dist\index.cjs.js:3:1)

√ Client-side fallback created: 200.html
√ Static manifest generated
i Generating sitemaps
√ Generated /sitemap.xml
√ Generated /sitemap.xml.gz

对于我导入firebase,我使用导入方法绕过SyntaxError: Cannot use import statement outside a module错误。例如:

import("https://www.gstatic.com/firebasejs/9.6.1/firebase-app.js").then(
(firebase) => {
    const firebaseConfig = {
        apiKey: "",
        authDomain: "",
        projectId: "",
        storageBucket: "",
        messagingSenderId: "",
        appId: "",
        measurementId: ""
    };
    const app = firebase.initializeApp(firebaseConfig);
    //...
});

当然,在您的情况下,您会 firebase/app 而不是远程 js,但这始终是另一种选择。

Firebase 的打包方式和 Nuxt 静态生成方式存在问题。

您可以在此处阅读更多相关信息 https://github.com/firebase/firebase-js-sdk/issues/5854

问题已通过升级到 Firebase JS SDK v9.6.3 得到解决