【发布时间】: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