简体   繁体   中英

node module not found .MODULE NOT FOUND

node app.js
node:internal/modules/cjs/loader:998
  throw err;
  ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\app.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
    at Module._load (node:internal/modules/cjs/loader:841:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []

i was trying to get the node code to work basically node app.js

Look into your project directory where you initialized node app.js . The issue is that you're not in the project directory where this file exists. Go into the project directory and launch your node app.js .

90% sure, hopefully this will fix it.

This error usually occurs when you're not in the right folder. Here you're in C:\Program Files\nodejs\node_modules\npm and you're trying to run your file App.js which is stored elsewhere on your computer.

I'd recommend going through these simple steps to fix the problem: (let's say you want Node to run your file App.js .

  1. Check whether or not your file exist in the current working directory (the error says it isn't there) with one of the commands:
    ls (bash, shell, powershell) or dir (cmd).
  • If your file ( App.js ) is listed on the output of the above command, then check the spelling and make sure the case exactly matches what you provided to node . That is you command must be node App or node App.js and not node app.js or node aPP.js ...

  • If your file isn't listed (what is the more probable outcome) then go to step 2 .


  1. Get the full path of the folder containing your file ( App.js ) from your file explorer.
  • On windows, just open the folder containing your file and copy the content of the address bar.
  • On Linux, refer to this question .
  • On Mac, refer to this other question

  1. In your terminal navigate to the above folder with the command
    cd copied_path .

  1. Check again the content of the path to make sure your command line is opened in the right folder.

  1. Run node App.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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