Reputation: 3
I have a problem with my Visual Studio.
Every time I run my Node.js code in Visual Studio I get an error.
internal/modules/cjs/loader.js:605
throw err;
^
Error: Cannot find module 'discord.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15)
at Function.Module._load (internal/modules/cjs/loader.js:529:25)
at Module.require (internal/modules/cjs/loader.js:658:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (d:\Code\AalBot\index.js:1:79)
at Module._compile (internal/modules/cjs/loader.js:722:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
I tried to reinstall Node with node install
but it don't work
npm WARN saveError ENOENT: no such file or directory, open 'C:\Users\Markus\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\Markus\package.json'
npm WARN Markus No description
npm WARN Markus No repository field.
npm WARN Markus No README data
npm WARN Markus No license field.
up to date in 1.901s
found 0 vulnerabilities
I tried also npm install
but it also doesn't work
npm WARN saveError ENOENT: no such file or directory, open 'C:\Users\Markus\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\Markus\package.json'
npm WARN Markus No description
npm WARN Markus No repository field.
npm WARN Markus No README data
npm WARN Markus No license field.
up to date in 1.901s
found 0 vulnerabilities
This is my Npm Version when I type npm version
in
{ npm: '6.4.1',
ares: '1.15.0',
cldr: '34.0',
http_parser: '2.8.0',
icu: '63.1',
modules: '67',
napi: '3',
nghttp2: '1.34.0',
node: '11.2.0',
openssl: '1.1.0i',
tz: '2018e',
unicode: '11.0',
uv: '1.23.2',
v8: '7.0.276.38-node.11',
zlib: '1.2.11' }
I hope you guys can help me, when you need more info, tell me :)
Upvotes: 0
Views: 346
Reputation: 2805
It's because you are using require('discord.js'), and npm is waiting for a npm module with that name.
If you want to import a module use
require('discord')
if it's a file
require('./discord.js')
Upvotes: 1
Reputation: 99
You need to run npm install
in the directory where your app lives. From the error message, it looks like you are running it from your home folder (which could of course be your app directory but I would assume not :)).
Edit: to be clear, run npm install
in your app root directory, where package.json
is located.
Upvotes: 1