[英]Error while running a Node js program
I have written a node js program which contained a method called AWS.config.update()
.我编写了一个节点 js 程序,其中包含一个名为AWS.config.update()
的方法。 When I tried to run it on terminal, I got an error:当我尝试在终端上运行它时,出现错误:
Error: Cannot find module 'aws-sdk'错误:找不到模块“aws-sdk”
Go to the folder where your node application is installed:转到安装节点应用程序的文件夹:
cd location/to/your/folder
And then run this to install the aws-sdk:然后运行它来安装 aws-sdk:
npm install aws-sdk
After npm install aws-sdk
be sure that your package.json specifies the exact version of the new dependency, such as:在npm install aws-sdk
之后,请确保您的 package.json 指定了新依赖项的确切版本,例如:
"dependencies": {
"aws-sdk": "2.4.12",
Refer https://www.npmjs.com/package/aws-sdk to see various ways to install aws-sdk
.请参阅https://www.npmjs.com/package/aws-sdk以查看安装aws-sdk
各种方法。
I prefer always adding dependency on package.json
我更喜欢总是添加对package.json
的依赖
"dependencies": {
"aws-sdk": "^2.182.0"
}
and run npm install
并运行npm install
I was trying to achieve same thing and got same error我试图实现同样的事情并得到同样的错误
I had installed aws-sdk
globally using npm i -g aws-sdk
我已经使用npm i -g aws-sdk
sdk 在全球范围内安装了aws-sdk
-sdk
Note running the node file from command line const AWS = require('aws-sdk')
would not work, if there is no local node_modules
folder which contains aws-sdk
请注意,如果没有包含aws-sdk
本地node_modules
文件夹,则从命令行const AWS = require('aws-sdk')
运行节点文件将不起作用
Solution only for MAC仅适用于 MAC 的解决方案const AWS = require('/usr/local/lib/node_modules/aws-sdk');
For other OS, find the location of globally installed node_modules对于其他操作系统,找到全局安装的 node_modules 的位置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.