[英]Cannot find module 'axios'
I am coding a small program for Firebase Functions, using node.js.我正在使用 node.js 为 Firebase 函数编写一个小程序。 I always install my node modules using npm and i also installed axios using npm only.
我总是使用 npm 安装我的节点模块,并且我还仅使用 npm 安装了 axios。
However when I do firebase deploy
I get this error:但是,当我执行
firebase deploy
时,我收到此错误:
This is my package-lock.json这是我的包裹锁。json
{
"requires": true,
"lockfileVersion": 1,
"dependencies": {
"axios": {
"version": "0.19.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.19.0.tgz",
"integrity": "sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==",
"requires": {
"follow-redirects": "1.5.10",
"is-buffer": "^2.0.2"
}
},
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
}
},
"follow-redirects": {
"version": "1.5.10",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
"integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
"requires": {
"debug": "=3.1.0"
}
},
"is-buffer": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.4.tgz",
"integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A=="
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
}
}
}
When I remove const axios = require('axios');
当我删除
const axios = require('axios');
from my index.js, the rest of my code compiles and works just fine.从我的 index.js 中,我的代码的 rest 可以编译并且工作得很好。
Any idea what is going on?知道发生了什么吗?
Thank you!谢谢!
Looks like you are missing axios dependency in your package.json
file.看起来您的
package.json
文件中缺少 axios 依赖项。
Go to the functions directory and install axios.转到functions目录并安装axios。 This will declare the axios dependency in the
package.json
for you.这将为您在
package.json
声明 axios 依赖项。 It works for me.这个对我有用。
npm install axios --save
Redeploy your Cloud Function for Firebase using:使用以下命令为 Firebase 重新部署 Cloud Functions 函数:
firebase deploy
Command prompt then go to your folder and npm install axios.命令提示符然后 go 到您的文件夹和 npm 安装 axios。 Finally, run the code.
最后,运行代码。 It worked for me
它对我有用
My answer may not fix your issue, but might help others.我的回答可能无法解决您的问题,但可能对其他人有所帮助。 I have received an error message "Uncaught Error Error: Cannot find module 'axios'" then I tried to install axios package by running the command npm install axios which fixed the problem.
I have received an error message "Uncaught Error Error: Cannot find module 'axios'" then I tried to install axios package by running the command npm install axios which fixed the problem.
Note: I had package.json empty (not even a pair of curly braces).注意:我的 package.json 是空的(甚至没有一对花括号)。 So running the nmp command was failing with error
所以运行 nmp 命令失败并出现错误
npm install axios npm 安装 axios
npm ERR! npm 错误! code EJSONPARSE So I added a pair of curly braces {} to my package.json and executed the same command again fixed the issue.
代码 EJSONPARSE所以我在我的 package.json 中添加了一对花括号 {} 并再次执行相同的命令解决了这个问题。
npm install axios npm 安装 axios
added 2 packages, and audited 3 packages in 1s新增2个包,1s审核3个包
1 package is looking for funding 1 package 正在寻找资金
run npm fund
for details运行
npm fund
了解详情
found 0 vulnerabilities发现0个漏洞
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.