简体   繁体   English

如果我尝试节点hello.js,则找不到模块是错误

[英]cannot find module is the error if i try node hello.js

I am trying this command to run my js file to check whether node is installed properly or not: C:\\Users\\vijay reddy\\hello.js 我正在尝试使用以下命令运行我的js文件,以检查节点是否已正确安装: C:\\Users\\vijay reddy\\hello.js

But I get this error: 但是我得到这个错误:

Error: Cannot find module 'C:\Users\vijay reddy\hello.js'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3

if you create a file hello.js like so: 如果您像这样创建文件hello.js

console.log('Hello World!');

And you are in the directory it exists in, and run (from your command prompt): 并且您在它所在的目录中,并运行(从命令提示符处):

node hello.js

You will get the correct output if node is installed correctly. 如果节点安装正确,您将获得正确的输出。

To figure out why it's not, try the other commands they suggest. 要弄清楚为什么不是,请尝试使用他们建议的其他命令。 If you try: 如果你试试:

node -v

and you get nothing, or an error, then that means either Node isn't installed, or it's not in your current users %PATH%. 并且您什么也没有得到,或者出现错误,则意味着未安装Node或您当前的用户%PATH%中没有它。

Also, depending on how you created hello.js, Windows may have "helpfully" changed it to hello.js.txt for you. 另外,根据您创建hello.js的方式,Windows可能已为您“有效地”将其更改为hello.js.txt。

May be my answer is not exactly relevant for this.But if you work on Windows OS and learning by creating manual files, another reason can be that windows saves files with the extension .txt. 可能我的答案与此并不完全相关。但是,如果您在Windows操作系统上工作并通过创建手动文件来学习,则另一个原因可能是Windows保存扩展名为.txt的文件。 That means, if you create a file with mouse click-> create empty document and save as yourFileName.js, The OS saves as yourFileName.js.txt. 这意味着,如果使用鼠标单击创建文件->创建空文档并另存为yourFileName.js,则操作系统另存为yourFileName.js.txt。 So better to go the file's directory in command line and type dir and list down files. 因此最好在命令行中进入文件目录,然后键入dir并列出文件。 It will show all files clearly. 它将清楚显示所有文件。

module error for hello.js was occured due to filelname mismatch error. 由于文件名不匹配错误,发生了hello.js的模块错误。

Please check file name on both command & directory by running dir command in application directory. 请通过在应用程序目录中运行dir命令来检查命令和目录中的文件名。

dir

Common filename error was hello.js is saved as hello.js.txt because extensions are hidden by default in some OS. 常见的文件名错误是hello.js被保存为hello.js.txt,因为扩展名在某些操作系统中默认为隐藏。 Make sure that preview extension was enabled in OS file manager. 确保在OS文件管理器中启用了预览扩展名。

Error: Cannot find module 'C:\\Users\\vijay reddy\\hello.js' 错误:找不到模块“ C:\\ Users \\ vijay reddy \\ hello.js”

You wrote it was saved to the desktop, then this line should look like this 您已将其保存到桌面,然后此行应如下所示

C:\\Users\\vijay reddy\\Desktop>node hello.js C:\\ Users \\ vijay reddy \\ Desktop> node hello.js

This most likely have something to do with you user inheritance level for your login to computer itself. 这很可能与您登录到计算机本身的用户继承级别有关。 It's stating you another path, try to save in Vijay reddy directly or make a guest name, that should always start in Document when using the cmd . 它说明了另一条路径,请尝试直接保存在Vijay reddy或命名为来宾名称,使用cmd时应始终以Document开头。

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

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