John Doe
John Doe

Reputation: 374

Why am I getting this error with npm, and how do I solve it?

I am trying to add a PayPal system into my html website. I am following this tutorial: https://www.youtube.com/watch?v=DNM9FdFrI1k&list=PL4eNesgScjZb3oktJK1786zI4nSET_tas&index=4

I am 9:10 into the video, and when I run npm run devStart as shown in the video, I get the following error:

PS C:\Users\dipla\OneDrive\Desktop\USB\Argo & coding\Examples\Web design\paypal-checkout> npm run devStart

> [email protected] devStart
> nodemon server.js

The system cannot find the path specified.
node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module 'C:\Users\dipla\OneDrive\Desktop\USB\nodemon\bin\nodemon.js'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

I have node.js installed and I added its location to my environmental variables.

This is my first time using npm and Node.js

EDIT

I finally found what is causing the error, but I don't know how to fix it. Here's what's happening: When I run npm i express ejs dotenv @paypal/checkout-server-sdk it installs the node_modules folder in my project, it places the files where you would expect, which in my case is:

C:\Users\dipla\OneDrive\Desktop\USB\Argo & coding\Examples\Web design\paypal-checkout\node_modules

But the computer is looking for the \node_modules files in 'C:\Users\dipla\OneDrive\Desktop\USB\nodemon\bin\nodemon.js'

Normally you would see this error if you run the commands in the terminal from the wrong directory, however my terminal says

PS D:\USB\Argo & coding\Examples\Web design\paypal-checkout>

and when I run dir I get

 PS D:\USB\Argo & coding\Examples\Web design\paypal-checkout> dir

 Directory: D:\USB\Argo & coding\Examples\Web design\paypal-checkout


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        2021-12-13  11:50 AM                node_modules
d-----        2021-12-09   6:57 PM                views
-a----        2021-12-13  11:50 AM         128194 package-lock.json
-a----        2021-12-13  11:50 AM            402 package.json
-a----        2021-12-13  11:25 AM            251 server.js

So, I tried moving the node_modules folder into the directory / my computer is looking, and it worked, however, this is not where I want to keep the node_modules files. It is a really bad location because when I make my website live, the mode_modules folder will not be inside my project folder, so it wont be included.

note: I am running this project from my USB. If I create the project from scratch NOT on my USB (directly on my desktop), I get the following error:

PS C:\Users\evand\Desktop\paypal-checkout> npm run devStart

> [email protected] devStart
> nodemon server.js

[nodemon] 2.0.15
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node server.js`
node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module 'node_modules/express'
Require stack:
- C:\Users\evand\Desktop\paypal-checkout\server.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\evand\Desktop\paypal-checkout\server.js:1:17)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'C:\\Users\\evand\\Desktop\\paypal-checkout\\server.js' ]
}
[nodemon] app crashed - waiting for file changes before starting...

So, my new question is: How do I make npm / my computer look for node_modules in a different directory?

Upvotes: 0

Views: 345

Answers (1)

Felipe Queiroz
Felipe Queiroz

Reputation: 19

I saw this solution, as you are using an external drive, this must be the problem

getting "Error: EINVAL: invalid argument, read" for "npm install --save-dev eslint --verbose"

"Since you are using drive letter I:, you might be on a portable drive. I had the same problem using an USB-Stick formatted on FAT32. I solved it reformatting to NTFS."

Upvotes: 1

Related Questions