简体   繁体   English

运行 Node.js 时找不到模块

[英]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.这是我第一次运行 node.js,我的文件位于 C:\source 中,名为 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.我检查了 node 是否安装了 node -v 并且版本号出现了,所以看起来很好。 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: index.js 有:

console.log('Hello World')

Looks like you need something like https://www.npmjs.com/package/cjs-module installed into your dependencies.看起来您需要将 https://www.npmjs.com/package/cjs-module安装到您的依赖项中。

This particular error is telling you, you have no CJS loader, and you are trying to reference that module.这个特定的错误告诉您,您没有 CJS 加载程序,并且您正在尝试引用该模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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