Firebase 函数在部署时抛出异常

Firebase functions throwing exception on deploy

我创建了一些 firebase 函数来在 firestore 中发生数据更改时发送通知。它在我的上一台计算机上运行良好,并且在每次更新时都能正确发送通知。

但是,当我更换计算机并尝试将 index.js、package.json 等所在的同一文件夹从我的旧计算机复制粘贴到新计算机时,问题就开始了。

现在,当我尝试通过在命令提示符中指定文件夹路径来使用命令时,它会抛出一些我在过去 5 天尝试修复但能够修复的错误。我对 firebase 函数及其命令有点陌生。

除了 index.js 之外,我将我所有的东西都粘贴在下面,因为它只有一个在上一台计算机上运行的功能。如果需要,我会把那个也贴在这里。

下面是我的函数文件夹。

.eslintrc:

module.exports = {
root: true,
env: {
es6: true,
node: true,
},
extends: [
"eslint:recommended",
"google",
],
rules: {
quotes: ["error", "double"],
},
};

package.json

     {
      "name": "functions",
      "description": "Cloud Functions for Firebase",
      "scripts": {
      "lint": "eslint .",
      "serve": "firebase emulators:start --only functions",
      "shell": "firebase functions:shell",
      "start": "npm run shell",
      "deploy": "firebase deploy --only functions",
      "logs": "firebase functions:log"
      },
      "engines": {
      "node": "14"
     },
    "main": "index.js",
    "dependencies": {
    "firebase-admin": "^9.8.0",
    "firebase-functions": "^3.14.1"
    },
   "devDependencies": {
   "eslint": "^7.6.0",
   "eslint-config-google": "^0.14.0",
   "firebase-functions-test": "^0.2.0"
   },
   "private": true
   }

npm 错误日志:

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\Program Files\nodejs\node.exe',
1 verbose cli   'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js',
1 verbose cli   '--prefix',
1 verbose cli   'D:\AmaKala_Project\functions',
1 verbose cli   'run',
1 verbose cli   'lint'
1 verbose cli ]
2 info using npm@6.14.15
3 info using node@v14.18.0
4 verbose run-script [ 'prelint', 'lint', 'postlint' ]
5 info lifecycle functions@~prelint: functions@
6 info lifecycle functions@~lint: functions@
7 verbose lifecycle functions@~lint: unsafe-perm in lifecycle true
8 verbose lifecycle functions@~lint: PATH: C:\Program 
Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp- 
bin;D:\AmaKala_Project\functions\node_modules\.bin;C:\Program Files 
(x86)\Common    Files\Oracle\Java\javapath;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\Syst 
 em32\WindowsPowerShell\v1.0\;C:\windows\System32\OpenSSH\;C:\Program 
 Files\Git\cmd;C:\ProgramFiles\nodejs\;C:\Users\Ranjit\AppData\Local\Microsoft\WindowsApps;C:\Users\ 
 Ranjit\AppData\Roaming\ 
 npm
 9 verbose lifecycle functions@~lint: CWD: D:\AmaKala_Project\functions
 10 silly lifecycle functions@~lint: Args: [ '/d /s /c', 'eslint .' ]
 11 silly lifecycle functions@~lint: Returned: code: 1  signal: null
 12 info lifecycle functions@~lint: Failed to exec lint script
 13 verbose stack Error: functions@ lint: `eslint .`
 13 verbose stack Exit status 1
 13 verbose stack     at EventEmitter.<anonymous> (C:\Program 
 Files\nodejs\node_modules\npm\node_modules\npm- 
 lifecycle\index.js:332:16)
 13 verbose stack     at EventEmitter.emit (events.js:400:28)
 13 verbose stack     at ChildProcess.<anonymous> (C:\Program 
 Files\nodejs\node_modules\npm\node_modules\npm- 
 lifecycle\lib\spawn.js:55:14)
 13 verbose stack     at ChildProcess.emit (events.js:400:28)
 13 verbose stack     at maybeClose (internal/child_process.js:1058:16)
 13 verbose stack     at Process.ChildProcess._handle.onexit 
 (internal/child_process.js:293:5)
 14 verbose pkgid functions@
 15 verbose cwd D:\AmaKala_Project
 16 verbose Windows_NT 10.0.19042
 17 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program 
 Files\nodejs\node_modules\npm\bin\npm-cli.js" "--prefix" 
 "D:\AmaKala_Project\functions" 
 "run" "lint"
 18 verbose node v14.18.0
 19 verbose npm  v6.14.15
 20 error code ELIFECYCLE
 21 error errno 1
 22 error functions@ lint: `eslint .`
 22 error Exit status 1
 23 error Failed at the functions@ lint script.
 23 error This is probably not a problem with npm. There is likely 
 additional logging output above.
 24 verbose exit [ 1, true ]

命令错误:

如果需要粘贴任何文件,请告诉我。 非常感谢

firebase.json

{
 "functions": {
 "source": "functions",
 "predeploy": [
  "npm --prefix \"$RESOURCE_DIR\" run lint"
 ]
}
}

做一件事删除 node_modules 然后先安装 npm

编辑:

您也可以参考这个link:https://github.com/firebase/firebase-tools/issues/822#issuecomment-406754186