【问题标题】:node.js simply does not runnode.js 根本不运行
【发布时间】:2012-03-21 10:43:20
【问题描述】:

我在我的 Mac 上安装并运行了 node.js,但即使我在 Windows 上执行此操作

chdir c:\testfolder
node example.js

然后我得到这个错误:

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
Error: Cannot find module 'c:\testfolder\example.js'

at Function._resolveFilename <module.js:322:11>
at Function._load <module.js:299:25>
at Array.0 <module.js:499:10>
at EventEmitter._tickCallback <node.js:192:40>

我什至只是尝试在 nodejs 网站上运行示例代码:

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

我不明白,那个文件确实存在!

【问题讨论】:

  • 您是如何安装 Node.js 的,您在 Windows 下在什么 shell 中运行它? (cmd.exe、command.com、Cygwin、Git Bash、PowerShell、一些我不知道的 shell?)我从来没有遇到过你在 Windows、Mac 或 Linux 上提到的问题。
  • 你确定文件存在吗...我不想问你是不是弄乱了文件扩展名之类的?尝试在我的 Windows 机器上运行这个 dl.dropbox.com/u/17781372/example.js - 5 分钟前安装的节点,它运行良好。
  • @DavidEllis 我刚刚使用了 Windows 安装程序,我正在使用 cmd.exe(我什至尝试右键单击并以管理员身份运行)
  • @MattEsch Esch 我知道鉴于错误,我一定看起来很疯狂,但文件确实存在。我也遇到了同样的错误。
  • @DavidEllis 我的路径:C:\Users\Smith>echo %PATH% C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x8 6)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\ Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\Program Files ( x86)\ATI Technologies\ATI.ACE\Core-Static;c:\Program Files (x86)\Common File s\Roxio Shared\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\12.0\ DLLShared\;C:\Program Files (x86)\Windows Live\Shared;C:\Users\Smith\AppData\ Roaming\npm;C:\Program Files (x86)\nodejs\

标签: node.js


【解决方案1】:

您的文件很可能不是名为 example.js,而是 example.js.txt,如果您是使用记事本创建的,并且您的计算机没有打开它以显示已知文件类型的文件扩展名:)

当您输入:chdir c:\testfolder 然后dir 时,您将能够看到您的真实文件名

【讨论】:

  • 不,恐怕不是这样。
  • 那么,我不确定还有什么情况。你能告诉我们“dir”命令说什么吗?无论如何,我真的认为在这种情况下(你报告的症状)没有其他问题,但你的文件没有命名为 example.js 而是一些不同的东西(大多数可能是 example.js.txt)。
  • 它不叫 .js.txt,我 1000% 确定:P
  • 然后尝试下载并安装最新版本...我刚刚这样做了,它工作得很好。我没有其他想法。
猜你喜欢
  • 1970-01-01
  • 2017-11-05
  • 1970-01-01
  • 1970-01-01
  • 2016-04-15
  • 1970-01-01
  • 1970-01-01
  • 2016-07-27
  • 1970-01-01
相关资源
最近更新 更多