如何在使用Firebase部署Quasar SSR项目时修复此错误?

huangapple go评论60阅读模式
英文:

How to fix this error when deploying quasar ssr project with firebase?

问题

I have several project build with quasar and firebase in ssr mode. Since today, I have the same error when I try to deploy a project when this command: firebase deploy --only functions:handler.

Build failed: internal/modules/cjs/loader.js:818
  throw err;
  ^

Error: Cannot find module '/layers/google.nodejs.runtime/node/bin/node_modules/npm/bin/npm-cli.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
Could not determine Node.js install directory; Error ID: b0ba1f57

Yet I do the exact same commands as usual: quasar build -m ssr and then firebase deploy --only functions:[functionName].

If I just deploy a function that is in the functions folder, everything happens normally...

Can anyone help me?

I see this in quasar doc: You will need to be running on “@quasar/app-webpack” v3.2+ to be able to use this feature. I had the 3.0.0 version and I updated the project to 3.9.2 version but still got the error.

My package.json file:

"dependencies": {
    "@quasar/extras": "^1.0.0",
    "algoliasearch": "^4.15.0",
    "core-js": "^3.6.5",
    "firebase": "^9.16.0",
    "firebase-admin": "^11.9.0",
    "firebase-functions": "^4.2.0",
    "intersection-observer": "^0.12.2",
    "quasar": "^2.6.0",
    "vue": "^3.0.0",
    "vue-i18n": "^9.0.0",
    "vue-instantsearch": "^4.8.7",
    "vue-router": "^4.0.0",
    "vuex": "^4.0.1",
    "vuex-persistedstate": "^4.1.0"
},
"devDependencies": {
    "@quasar/app-webpack": "^3.9.2",
    "workbox-webpack-plugin": "^6.5.4"
},

Thank you

Here is my production-export.js file:

import * as functions from 'firebase-functions'
import { ssrProductionExport } from 'quasar/wrappers'

export default ssrProductionExport(({ ssrHandler }) => {
  return {
    handler: functions.https.onRequest(ssrHandler)
  }
})

Here is my firebase.json file:

{
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "hosting": {
    "public": "dist/ssr",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "function": "handler"
      }
    ]
  },
  "storage": {
    "rules": "storage.rules"
  },
  "functions": {
    "source": "dist/ssr"
  }
}

And finally, my dist/ssr/package.json file:

"dependencies": {
    "algoliasearch": "4.15.0",
    "core-js": "3.27.2",
    "firebase": "9.16.0",
    "firebase-admin": "^11.9.0",
    "firebase-functions": "^4.2.0",
    "intersection-observer": "0.12.2",
    "quasar": "2.11.5",
    "vue": "3.2.45",
    "vue-i18n": "9.2.2",
    "vue-instantsearch": "4.8.7",
    "vue-router": "4.1.6",
    "vuex": "4.1.0",
    "vuex-persistedstate": "4.1.0",
    "compression": "^1.0.0",
    "express": "^4.0.0",
    "@quasar/ssr-helpers": "2.2.2",
    "@quasar/babel-preset-app": "2.0.2"
},
"engines": {
    "node": "16",
    "npm": ">= 6.13.4",
    "yarn": ">= 1.21.1"
},
"browserslist": [
    "last 10 Chrome versions",
    "last 10 Firefox versions",
    "last 4 Edge versions",
    "last 7 Safari versions",
    "last 8 Android versions",
    "last 8 ChromeAndroid versions",
    "last 8 FirefoxAndroid versions",
    "last 10 iOS versions",
    "last 5 Opera versions"
],
"quasar": {
    "ssr": true
}
英文:

I have several project build with quasar and firebase in ssr mode. Since today, I have the same error when I try to deploy a project when this command: firebase deploy --only functions:handler.

Build failed: internal/modules/cjs/loader.js:818
  throw err;
  ^

Error: Cannot find module '/layers/google.nodejs.runtime/node/bin/node_modules/npm/bin/npm-cli.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
Could not determine Node.js install directory; Error ID: b0ba1f57

Yet I do the exact same commands as usual: quasar build -m ssr and then firebase deploy --only functions:[functionName].

If I just deploy a function that is in the functions folder, everything happens normally...

Can anyone help me?

I seethis in quasar doc: You will need to be running on “@quasar/app-webpack” v3.2+ to be able to use this feature. Ihad the 3.0.0 version and i updated the project to 3.9.2 version but still got error.

My package.json file:

  "dependencies": {
    "@quasar/extras": "^1.0.0",
    "algoliasearch": "^4.15.0",
    "core-js": "^3.6.5",
    "firebase": "^9.16.0",
    "firebase-admin": "^11.9.0",
    "firebase-functions": "^4.2.0",
    "intersection-observer": "^0.12.2",
    "quasar": "^2.6.0",
    "vue": "^3.0.0",
    "vue-i18n": "^9.0.0",
    "vue-instantsearch": "^4.8.7",
    "vue-router": "^4.0.0",
    "vuex": "^4.0.1",
    "vuex-persistedstate": "^4.1.0"
  },
  "devDependencies": {
    "@quasar/app-webpack": "^3.9.2",
    "workbox-webpack-plugin": "^6.5.4"
  },

Thank you

Here is my production-export.js file:

import * as functions from 'firebase-functions'
import { ssrProductionExport } from 'quasar/wrappers'

export default ssrProductionExport(({ ssrHandler }) => {
  return {
    handler: functions.https.onRequest(ssrHandler)
  }
})

here is my firebase.json file:

{
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "hosting": {
    "public": "dist/ssr",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "function": "handler"

      }
    ]
  },
  "storage": {
    "rules": "storage.rules"
  },
  "functions": {
    "source": "dist/ssr"
  }

}

and finally my dist/ssr/package.json file

  "dependencies": {
    "algoliasearch": "4.15.0",
    "core-js": "3.27.2",
    "firebase": "9.16.0",
    "firebase-admin": "^11.9.0",
    "firebase-functions": "^4.2.0",
    "intersection-observer": "0.12.2",
    "quasar": "2.11.5",
    "vue": "3.2.45",
    "vue-i18n": "9.2.2",
    "vue-instantsearch": "4.8.7",
    "vue-router": "4.1.6",
    "vuex": "4.1.0",
    "vuex-persistedstate": "4.1.0",
    "compression": "^1.0.0",
    "express": "^4.0.0",
    "@quasar/ssr-helpers": "2.2.2",
    "@quasar/babel-preset-app": "2.0.2"
  },
  "engines": {
    "node": "16",
    "npm": ">= 6.13.4",
    "yarn": ">= 1.21.1"
  },
  "browserslist": [
    "last 10 Chrome versions",
    "last 10 Firefox versions",
    "last 4 Edge versions",
    "last 7 Safari versions",
    "last 8 Android versions",
    "last 8 ChromeAndroid versions",
    "last 8 FirefoxAndroid versions",
    "last 10 iOS versions",
    "last 5 Opera versions"
  ],
  "quasar": {
    "ssr": true
  }
}

答案1

得分: 1

我们遇到了相同的问题,似乎是新版本的 npm(9.7.0)引起的。

我们通过以下方式解决了这个问题:

  • package.jsonengines 中排除了该版本:
"engines": {
  "npm": "9 - 9.6.x || >9.7.0", // 当发布 9.7.1 时仍会更新
  /* 其他引擎 */
},
  • 运行 npm i 来更新锁定文件。
  • 在下一次部署时(我们使用应用引擎),使用 --no-cache

希望对您有所帮助!

英文:

We had the same issue, it seems that the new version of npm (9.7.0) is causing this.

We fixed it by:

  • excluding that version from the

    engines in package.json:

       "engines": {
           "npm": "9 - 9.6.x || >9.7.0", // will still update to 9.7.1 when released
         /* other engines */
       },
    
  • running npm i to update the lock file as well.

  • using --no-cache on our next deployment (we use app engine)

Hope it helps !

huangapple
  • 本文由 发表于 2023年6月2日 03:09:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76384997.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定