Firebase 节点错误:找不到模块“axios”

Firebase Node Error: Cannot find module 'axios'

提问人:Edmund Rojas 提问时间:11/11/2023 最后编辑:Edmund Rojas 更新时间:11/11/2023 访问量:21

问:

我正在尝试在我的 firebase 项目的计划函数中使用 axios,我安装了它,当我将它与我已经使用了一段时间的其他依赖项一起列出时可以看到它,但是当我将其导入我的项目时,我收到以下错误:

Function failed on loading user code. This is likely due to a bug in the user code. 
Error message: Provided module can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'axios'
Require stack:
- /workspace/index.js
- /layers/google.nodejs.functions-framework/functions-framework/node_modules/@google- 
cloud/functions-framework/build/src/loader.js
- /layers/google.nodejs.functions-framework/functions-framework/node_modules/@google- 
cloud/functions-framework/build/src/main.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1028:15)
    at Function.Module._load (node:internal/modules/cjs/loader:873:27)
    at Module.require (node:internal/modules/cjs/loader:1100:19)
    at require (node:internal/modules/cjs/helpers:119:18)
    at Object.<anonymous> (/workspace/index.js:7:15)
    at Module._compile (node:internal/modules/cjs/loader:1198:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
    at Module.load (node:internal/modules/cjs/loader:1076:32)
    at Function.Module._load (node:internal/modules/cjs/loader:911:12)
    at Module.require (node:internal/modules/cjs/loader:1100:19)

当我运行 npm list 时,我得到这个:

├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

我也尝试安装和运行请求并遇到类似的问题,但获取工作正常,我也尝试手动将其添加到我的package.json中,但这也引发了错误,如果这有助于理解问题,我将在下面发布我的导入代码:

const axios = require("axios");

const WEBHOOK_URL = "test";
const text = "Webhook test: ";
axios.post(WEBHOOK_URL, {
  text: text,
}).then((res) => {
  console.log(res);
}).catch((err) => {
  console.error(err.toJSON());
d});
节点.js Firebase axios google-cloud-functions http-post

评论


答: 暂无答案