【问题标题】:Error: Cannot find module 'C:\server.js' in Node server for Meanjs错误:在 Meanjs 的节点服务器中找不到模块“C:\server.js”
【发布时间】:2017-09-26 23:09:28
【问题描述】:

我已经 git 将 meanjs 克隆到 D: 驱动器的文件夹中,如下所示,并运行命令 npm start 启动节点服务器。

admin@admin-PC MINGW32 /d/Udemy Angular 1 projects/Project5/jobfinder (master)
$ npm start

> meanjs@0.5.0 start D:\Udemy Angular 1 projects\Project5\jobfinder
> gulp

[23:41:30] Using gulpfile D:\Udemy Angular 1 projects\Project5\jobfinder\gulpfile.js

....并得到以下错误。

Error: Cannot find module 'C:\server.js'
    at Function.Module._resolveFilename (module.js:455:15)
    at Function.Module._load (module.js:403:25)
    at Module.runMain (module.js:590:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3
[23:58:35] [nodemon] app crashed - waiting for file changes before starting...

之后,为了试一试,我将 server.js 从当前目录复制到 C:\ 并从同一目录在 git bash 中发出“npm start”命令,错误变为以下。

Debugger listening on [::]:5858
module.js:457
throw err;
^

Error: Cannot find module './config/lib/app'
    at Function.Module._resolveFilename (module.js:455:15)
    at Function.Module._load (module.js:403:25)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\server.js:6:11)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
[23:41:52] [nodemon] app crashed - waiting for file changes before starting...

谁能帮我理解为什么 Node 在 C:\ 而不是当前目录中寻找 server.js 和其他资源?有什么非常简单的东西我错过了(尽管我觉得很奇怪!)。顺便说一句,很抱歉将 git bash 错误作为代码发布,因为我没有足够的声誉来发布多个图片链接。

干杯!

添加我的研究......

在 meanjs 目录中调用 'npm start' 命令会命中文件 gulpfile.js。查看文件,我看到如下启动了一个 gulp 任务(nodemon),并且返回对象的脚本属性设置为“server.js”。

来自 gulpfile.js 的代码。

gulp.task('nodemon', function () {

  var nodeVersions = process.versions;
  var debugArgument = '--debug';
  switch (nodeVersions.node.substr(0, 1)) {
    case '4':
    case '5':
    case '6':
    debugArgument = '--debug';
    break;
    case '7':
      debugArgument = '--inspect';
      break;
  }
  console.log('nodemon task'); // checking execution of the callback
  return plugins.nodemon({
    script: 'server.js',
    nodeArgs: [debugArgument],
    ext: 'js,html',
    verbose: true,
    watch: _.union(defaultAssets.server.views, defaultAssets.server.allJS, defaultAssets.server.config)
  });
});

【问题讨论】:

    标签: node.js gulp meanjs nodemon


    【解决方案1】:

    通过删除注册表中以下路径的Autorun字符串解决了上述问题。

    “HKEY_CURRENT_USER\Software\Microsoft\Command Processor”。

    自动运行字符串设置为 C:,因此 Nodemon 将 C: 识别为根目录,而不是 Gitbash 或命令提示符中的当前目录。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-17
      • 2020-12-15
      • 2013-03-22
      • 1970-01-01
      • 2015-10-09
      • 2019-11-18
      • 1970-01-01
      • 2018-11-07
      相关资源
      最近更新 更多