firebase / firebase-tools

The Firebase Command Line Tools
MIT License
4.01k stars 925 forks source link

Firebase deploy failing potentially due to npm version < 7 #5388

Closed MiroStW closed 1 year ago

MiroStW commented 1 year ago

[REQUIRED] Environment info

firebase-tools: 11.19.0

Platform: macOS Ventura

node: 18.12.1 npm 8.19.2

[REQUIRED] Test case

package.json:

{
  "name": "shared-lists",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "NODE_OPTIONS='--inspect' next dev",
    "emulate": "firebase emulators:start",
    "serve": "npm run build && firebase emulators:start",
    "build": "next build",
    "start": "next start",
    "lint": "next lint",
    "deploy": "firebase deploy --only functions,hosting"
  },
  "main": "src/firebase/firebaseFunctions.js",
  "dependencies": {
    "@dnd-kit/core": "^6.0.5",
    "@dnd-kit/modifiers": "^6.0.0",
    "@dnd-kit/sortable": "^7.0.1",
    "cors": "^2.8.5",
    "firebase": "^9.9.3",
    "firebase-admin": "^11.0.1",
    "firebase-functions": "^4.1.1",
    "firebase-tools": "^11.19.0",
    "firebaseui": "^6.0.1",
    "material-icons": "^1.11.8",
    "next": "^12.3.4",
    "next-cookie": "^2.8.0",
    "next-cookies": "^2.0.3",
    "nodemailer": "^6.7.8",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-firebase-hooks": "^5.0.3"
  },
  "devDependencies": {
    "@types/node": "^18.6.2",
    "@types/nodemailer": "^6.4.6",
    "@types/react": "^18.0.15",
    "@types/react-dom": "18.0.6",
    "@typescript-eslint/eslint-plugin": "^5.31.0",
    "@typescript-eslint/parser": "^5.31.0",
    "eslint": "^8.23.0",
    "eslint-config-airbnb-base": "^15.0.0",
    "eslint-config-next": "^12.2.5",
    "eslint-config-prettier": "^8.5.0",
    "eslint-plugin-import": "^2.26.0",
    "prettier": "^2.7.1",
    "typescript": "^4.7.4"
  }
}

firebase.json:

{
  "functions": {
    "source": ".",
    "ignore": [
      ".firebase/**",
      ".firebaserc",
      "firebase.json",
      "**/node_modules/**",
      "**/public/**",
      ".git",
      "firebase-debug.log",
      "firebase-debug.*.log"
    ],
    "predeploy": [
      "npm --prefix \"$PROJECT_DIR\" install",
      "rm -r build",
      "npm --prefix \"$PROJECT_DIR\" run build"
    ],
    "runtime": "nodejs16"
  },
  "firestore": {
    "rules": "src/firebase/firestore.rules",
    "indexes": "src/firebase/firestore.indexes.json"
  },
  "hosting": {
    "public": "public",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    "rewrites": [
      {
        "source": "**",
        "function": "nextjsFunc"
      }
    ]
  },
  "emulators": {
    "auth": {
      "port": 9099
    },
    "functions": {
      "port": 5001
    },
    "firestore": {
      "port": 8080
    },
    "hosting": {
      "port": 4100
    },
    "ui": {
      "enabled": true
    }
  }
}

[REQUIRED] Steps to reproduce

run firebase deploy

[REQUIRED] Expected behavior

App is being deployed across hosting, functions, firestore, ... This worked a few days ago without issues.

[REQUIRED] Actual behavior

[2023-01-03T20:19:27.563Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2023-01-03T20:19:27.564Z] > authorizing via signed-in user (flair2k@gmail.com)
[2023-01-03T20:19:27.564Z] [iam] checking project shared-lists-8fc29 for permissions ["cloudfunctions.functions.create","cloudfunctions.functions.delete","cloudfunctions.functions.get","cloudfunctions.functions.list","cloudfunctions.functions.update","cloudfunctions.operations.get","datastore.indexes.create","datastore.indexes.delete","datastore.indexes.list","datastore.indexes.update","firebase.projects.get","firebasehosting.sites.update"]
[2023-01-03T20:19:27.565Z] > refreshing access token with scopes: []
[2023-01-03T20:19:27.565Z] >>> [apiv2][query] POST https://www.googleapis.com/oauth2/v3/token [none]
[2023-01-03T20:19:27.566Z] >>> [apiv2][body] POST https://www.googleapis.com/oauth2/v3/token [omitted]
[2023-01-03T20:19:28.189Z] <<< [apiv2][status] POST https://www.googleapis.com/oauth2/v3/token 200
[2023-01-03T20:19:28.189Z] <<< [apiv2][body] POST https://www.googleapis.com/oauth2/v3/token [omitted]
[2023-01-03T20:19:28.240Z] >>> [apiv2][query] POST https://cloudresourcemanager.googleapis.com/v1/projects/shared-lists-8fc29:testIamPermissions [none]
[2023-01-03T20:19:28.240Z] >>> [apiv2][(partial)header] POST https://cloudresourcemanager.googleapis.com/v1/projects/shared-lists-8fc29:testIamPermissions x-goog-quota-user=projects/shared-lists-8fc29
[2023-01-03T20:19:28.240Z] >>> [apiv2][body] POST https://cloudresourcemanager.googleapis.com/v1/projects/shared-lists-8fc29:testIamPermissions {"permissions":["cloudfunctions.functions.create","cloudfunctions.functions.delete","cloudfunctions.functions.get","cloudfunctions.functions.list","cloudfunctions.functions.update","cloudfunctions.operations.get","datastore.indexes.create","datastore.indexes.delete","datastore.indexes.list","datastore.indexes.update","firebase.projects.get","firebasehosting.sites.update"]}
[2023-01-03T20:19:28.320Z] <<< [apiv2][status] GET https://firebase-public.firebaseio.com/cli.json 200
[2023-01-03T20:19:28.320Z] <<< [apiv2][body] GET https://firebase-public.firebaseio.com/cli.json {"cloudBuildErrorAfter":1594252800000,"cloudBuildWarnAfter":1590019200000,"defaultNode10After":1594252800000,"minVersion":"3.0.5","node8DeploysDisabledAfter":1613390400000,"node8RuntimeDisabledAfter":1615809600000,"node8WarnAfter":1600128000000}
[2023-01-03T20:19:28.538Z] <<< [apiv2][status] POST https://cloudresourcemanager.googleapis.com/v1/projects/shared-lists-8fc29:testIamPermissions 200
[2023-01-03T20:19:28.538Z] <<< [apiv2][body] POST https://cloudresourcemanager.googleapis.com/v1/projects/shared-lists-8fc29:testIamPermissions {"permissions":["cloudfunctions.functions.create","cloudfunctions.functions.delete","cloudfunctions.functions.get","cloudfunctions.functions.list","cloudfunctions.functions.update","cloudfunctions.operations.get","datastore.indexes.create","datastore.indexes.delete","datastore.indexes.list","datastore.indexes.update","firebase.projects.get","firebasehosting.sites.update"]}
[2023-01-03T20:19:28.538Z] >>> [apiv2][query] POST https://iam.googleapis.com/v1/projects/shared-lists-8fc29/serviceAccounts/shared-lists-8fc29@appspot.gserviceaccount.com:testIamPermissions [none]
[2023-01-03T20:19:28.538Z] >>> [apiv2][body] POST https://iam.googleapis.com/v1/projects/shared-lists-8fc29/serviceAccounts/shared-lists-8fc29@appspot.gserviceaccount.com:testIamPermissions {"permissions":["iam.serviceAccounts.actAs"]}
[2023-01-03T20:19:28.811Z] <<< [apiv2][status] POST https://iam.googleapis.com/v1/projects/shared-lists-8fc29/serviceAccounts/shared-lists-8fc29@appspot.gserviceaccount.com:testIamPermissions 200
[2023-01-03T20:19:28.812Z] <<< [apiv2][body] POST https://iam.googleapis.com/v1/projects/shared-lists-8fc29/serviceAccounts/shared-lists-8fc29@appspot.gserviceaccount.com:testIamPermissions {"permissions":["iam.serviceAccounts.actAs"]}
[2023-01-03T20:19:28.813Z] >>> [apiv2][query] GET https://firebase.googleapis.com/v1beta1/projects/shared-lists-8fc29 [none]
[2023-01-03T20:19:29.215Z] <<< [apiv2][status] GET https://firebase.googleapis.com/v1beta1/projects/shared-lists-8fc29 200
[2023-01-03T20:19:29.215Z] <<< [apiv2][body] GET https://firebase.googleapis.com/v1beta1/projects/shared-lists-8fc29 {"projectId":"shared-lists-8fc29","projectNumber":"551816293327","displayName":"shared-lists","name":"projects/shared-lists-8fc29","resources":{"hostingSite":"shared-lists-8fc29","storageBucket":"shared-lists-8fc29.appspot.com","locationId":"europe-west3"},"state":"ACTIVE","etag":"1_53fce6f1-ba48-477f-ac2c-f7a7b61d6aec"}

=== Deploying to 'shared-lists-8fc29'...

i  deploying firestore, functions, hosting 
Running command: npm --prefix "$PROJECT_DIR" install
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!

> core-js-pure@3.27.1 postinstall /Users/xxx/Documents/coding/shared-lists/node_modules/core-js-pure
> node -e "try{require('./postinstall')}catch(e){}"

node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module '/Users/xxx/Documents/coding/shared-lists/node_modules/core-js-pure/-e'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function._resolveFilename (pkg/prelude/bootstrap.js:1955:46)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Function.runMain (pkg/prelude/bootstrap.js:1983:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @next/swc-linux-arm64-gnu@12.3.4 (node_modules/@next/swc-linux-arm64-gnu):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @next/swc-linux-arm64-gnu@12.3.4: wanted {"os":"linux","arch":"arm64"} (current: {"os":"darwin","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @next/swc-linux-arm64-musl@12.3.4 (node_modules/@next/swc-linux-arm64-musl):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @next/swc-linux-arm64-musl@12.3.4: wanted {"os":"linux","arch":"arm64"} (current: {"os":"darwin","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @next/swc-android-arm64@12.3.4 (node_modules/@next/swc-android-arm64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @next/swc-android-arm64@12.3.4: wanted {"os":"android","arch":"arm64"} (current: {"os":"darwin","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @next/swc-linux-x64-gnu@12.3.4 (node_modules/@next/swc-linux-x64-gnu):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @next/swc-linux-x64-gnu@12.3.4: wanted {"os":"linux","arch":"x64"} (current: {"os":"darwin","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @next/swc-freebsd-x64@12.3.4 (node_modules/@next/swc-freebsd-x64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @next/swc-freebsd-x64@12.3.4: wanted {"os":"freebsd","arch":"x64"} (current: {"os":"darwin","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @next/swc-android-arm-eabi@12.3.4 (node_modules/@next/swc-android-arm-eabi):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @next/swc-android-arm-eabi@12.3.4: wanted {"os":"android","arch":"arm"} (current: {"os":"darwin","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @next/swc-win32-x64-msvc@12.3.4 (node_modules/@next/swc-win32-x64-msvc):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @next/swc-win32-x64-msvc@12.3.4: wanted {"os":"win32","arch":"x64"} (current: {"os":"darwin","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @next/swc-linux-arm-gnueabihf@12.3.4 (node_modules/@next/swc-linux-arm-gnueabihf):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @next/swc-linux-arm-gnueabihf@12.3.4: wanted {"os":"linux","arch":"arm"} (current: {"os":"darwin","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @next/swc-darwin-arm64@12.3.4 (node_modules/@next/swc-darwin-arm64):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @next/swc-darwin-arm64@12.3.4: wanted {"os":"darwin","arch":"arm64"} (current: {"os":"darwin","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @next/swc-linux-x64-musl@12.3.4 (node_modules/@next/swc-linux-x64-musl):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @next/swc-linux-x64-musl@12.3.4: wanted {"os":"linux","arch":"x64"} (current: {"os":"darwin","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @next/swc-win32-ia32-msvc@12.3.4 (node_modules/@next/swc-win32-ia32-msvc):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @next/swc-win32-ia32-msvc@12.3.4: wanted {"os":"win32","arch":"ia32"} (current: {"os":"darwin","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: @next/swc-win32-arm64-msvc@12.3.4 (node_modules/@next/swc-win32-arm64-msvc):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for @next/swc-win32-arm64-msvc@12.3.4: wanted {"os":"win32","arch":"arm64"} (current: {"os":"darwin","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! core-js-pure@3.27.1 postinstall: `node -e "try{require('./postinstall')}catch(e){}"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the core-js-pure@3.27.1 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/xxx/.npm/_logs/2023-01-03T20_19_41_957Z-debug.log

Error: functions predeploy error: Command terminated with non-zero exit code 1

resolution attempts

So far I believe the problem to be with related to node version, as I have never seen the warning in the first log line:

npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!

I restricted the allowed versions in package.json using

  "engines": {
    "npm": ">=7.24",
    "node": ">=16.13"
  },

and an .npmrc file with engine-strict=true to enforce a npm version compatible with lockfileVersion@2

Then a firebase deploy results in

i  deploying firestore, functions, hosting
Running command: npm --prefix "$PROJECT_DIR" install
npm ERR! code ENOTSUP
npm ERR! notsup Unsupported engine for shared-lists@0.1.0: wanted: {"npm":">=7.24","node":">=16.13"} (current: {"node":"16.16.0","npm":"6.14.17"})
npm ERR! notsup Not compatible with your version of node/npm: shared-lists@0.1.0
npm ERR! notsup Not compatible with your version of node/npm: shared-lists@0.1.0
npm ERR! notsup Required: {"npm":">=7.24","node":">=16.13"}
npm ERR! notsup Actual:   {"npm":"6.14.17","node":"16.16.0"}

This suggests, that in fact an incompatible version of npm (<7) is used. However running npm version tells me I am using npm: '8.19.2' and node: '18.12.1'

MiroStW commented 1 year ago

nevermind, a reboot helped for whatever reason 😌 if any further input from my side can help someone else, please let me know