【问题标题】:Firebase functions Error: Cannot find module 'diagnostics'Firebase 函数错误:找不到模块“诊断”
【发布时间】:2020-10-29 11:18:56
【问题描述】:

当我在我的函数目录中运行firebase deploy --only functions 时,我一直看到这个错误。我明白了:

Error: Cannot find module 'diagnostics'
Require stack:
- C:\Users\Johnson\AppData\Roaming\nvm\v12.16.1\node_modules\firebase-tools\node_modules\winston\lib\winston\exception-handler.js
- C:\Users\Johnson\AppData\Roaming\nvm\v12.16.1\node_modules\firebase-tools\node_modules\winston\lib\winston\logger.js
- C:\Users\Johnson\AppData\Roaming\nvm\v12.16.1\node_modules\firebase-tools\node_modules\winston\lib\winston\create-logger.js
- C:\Users\Johnson\AppData\Roaming\nvm\v12.16.1\node_modules\firebase-tools\node_modules\winston\lib\winston.js
- C:\Users\Johnson\AppData\Roaming\nvm\v12.16.1\node_modules\firebase-tools\lib\logger.js
- C:\Users\Johnson\AppData\Roaming\nvm\v12.16.1\node_modules\firebase-tools\lib\index.js
- C:\Users\Johnson\AppData\Roaming\nvm\v12.16.1\node_modules\firebase-tools\lib\bin\firebase.js

这是我package.json的内容:

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "engines": {
    "node": "10"
  },
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase serve --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "dependencies": {
    "@woocommerce/woocommerce-rest-api": "^1.0.1",
    "algoliasearch": "^4.0.3",
    "firebase-admin": "^8.6.0",
    "firebase-functions": "^3.6.1",
    "moment": "^2.24.0",
    "node-mailjet": "^3.3.1"
  },
  "devDependencies": {
    "eslint": "^5.12.0",
    "eslint-plugin-promise": "^4.0.1"
  },
  "private": true
}

我最近(几周前)将我的函数目录从节点 8 更新到节点 10,不确定这是否与此问题有关。我试过删除node_modules 文件夹和package-lock.json 并运行npm install。我也尝试过运行npm install -g firebase-tools,然后运行firebase deploy --only functions,但错误仍然存​​在。请问,怎么办?

【问题讨论】:

    标签: node.js firebase npm google-cloud-functions


    【解决方案1】:

    我已经解决了这个问题。我只是从 npm 全局卸载了 firebase-tools 并重新安装。该问题可能是在我的 PC 上运行 Windows 还原的副作用(感谢 Windows!)

    【讨论】:

      【解决方案2】:

      有一个简单的解决方案可以解决许多这些节点/npm 问题。首先,使用以下命令安装纱线: npm install -g 纱线

      然后使用 yarn 为您的项目示例安装所有节点模块:

      添加 your_node_module

      yarn add global your_node_modue(用于全局安装)

      例如,如果您想使用 firebase 命令,但出现错误或显示“找不到命令”,请执行以下操作:

      yarn firebase 初始化

      yarn firebase 部署

      等等……

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-05-24
        • 1970-01-01
        • 2020-10-06
        • 1970-01-01
        • 2019-12-12
        • 2018-03-31
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多