简体   繁体   English

运行节点时找不到模块“请求”

[英]Can't find module 'request' when running a node

I'm trying to run a nodejs file, but whenever I run it, I get the error: 我正在尝试运行一个nodejs文件,但是每当我运行它时,都会出现错误:

Error: Cannot find module 'request'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
at Function.Module._load (internal/modules/cjs/loader.js:506:25)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (C:\Users\MYUSERNAME\Documents\njtest\web-api-auth-examples-master\authorization_code\app.js:11:15)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)

I had a similar error with a different module, and all I did was download it and the error went away, but I downloaded the request module, and I'm still getting the error. 我在不同的模块上遇到了类似的错误,我所做的只是下载了该错误,错误消失了,但是我下载了请求模块,但仍然出现错误。 I have all the files from here downloaded and in the file path C:\\Users\\USer\\Documents\\njtest, and it shows the Request Master folder. 我从这里下载了所有文件,并在文件路径C:\\ Users \\ USer \\ Documents \\ njtest中,它显示了Request Master文件夹。 This is for trying to do authentication with the spotify API by the way. 这是为了尝试通过Spotify API进行身份验证。 Any ideas on to why it's still giving the error? 关于为什么它仍然给出错误的任何想法? I'm guessing maybe the file needs to be somewhere else? 我猜测文件可能需要放在其他地方? Thanks! 谢谢!

Fwiw, I found that my request package was declared in devDependencies in package.json automatically and when I declared it in the dependencies object instead, this resolved the issue for me. 首先,我发现我的请求包是在package.json devDependencies中自动声明的,而当我在dependencies对象中声明它时,这为我解决了这个问题。

If yours is in dependencies already, that may not be your issue, but it is worth checking. 如果您已经在dependencies ,那可能不是您的问题,但是值得检查。

Regarding the difference in the two objects, devDependencies and dependencies : 关于两个对象devDependenciesdependencies的区别:

The difference between these two, is that devDependencies are modules which are only required during development, while dependencies are modules which are also required at runtime. 两者之间的区别在于,devDependencies是仅在开发期间需要的模块,而dependencies是在运行时也需要的模块。

( https://medium.com/@dylanavery720/npmmmm-1-dev-dependencies-dependencies-8931c2583b0c ) https://medium.com/@dylanavery720/npmmmm-1-dev-dependencies-dependencies-8931c2583b0c

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM