简体   繁体   中英

Cannot find Module when running Node.js

This is my first time running node.js, and I have file located in C:\source, called index.js. I am not sure what am doing wrong here. I checked if node was installed with node -v and the version number appeared so that seems fine. Any input?

C:\source>node index.js
internal/modules/cjs/loader.js:783
    throw err;
    ^

Error: Cannot find module 'C:\source\index.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:780:15)
    at Function.Module._load (internal/modules/cjs/loader.js:685:27)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1014:10)
    at internal/main/run_main_module.js:17:11 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

index.js has:

console.log('Hello World')

Looks like you need something like https://www.npmjs.com/package/cjs-module installed into your dependencies.

This particular error is telling you, you have no CJS loader, and you are trying to reference that module.

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