简体   繁体   中英

Node.JS can't find Module inside Folder

I made a folder. Then cloned code from GH into it. so it's a folder inside my folder. I run (node index.js) and it throws 'error, module not found. What can I do differently?

`josh@Joshs-MBP random % node index.js
node:internal/modules/cjs/loader:927
  throw err;
  ^

Error: Cannot find module '/Users/josh/Desktop/random/index.js'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}josh@Joshs-MBP random % `

Problem -

Running node index.js throws a module not found error.

Solution -

You need to change directory one directory level deeper.

You are currently in

/Users/josh/Desktop/random/index.js

You said you created a directory, then put a Github repo inside of that directory. That means you need to change directory into the Github repo still.

If you look at the error it shows that you are running node index.js inside of a directory on your Desktop.

Based on your description of putting a Github repo inside of a directory you created, you likely need to use cd to move into it.

Solution -

  1. cd repoName

  2. ls to verify index.js is in the current location.

  3. When you see index.js in the output from ls type node index.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