找不到模块app.js?

ric*_*rth 2 node.js express

我在服务器目录中启动节点app.js,我得到以下内容:

module.js:544
    throw err;
    ^

Error: Cannot find module 'server/server/app.js'
    at Function.Module._resolveFilename (module.js:542:15)
    at Function.Module._load (module.js:472:25)
    at Function.Module.runMain (module.js:682:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:613:3
[nodemon] app crashed - waiting for file changes before starting...
Run Code Online (Sandbox Code Playgroud)

如何解决这个问题?它以前工作,现在它正在寻找一个奇怪的路径/服务器/服务器而不仅仅是/ server.

我刚刚将节点重新安装到一个更新的版本,从5.到最新的稳定版.

JSc*_*her 5

您很可能尝试加载模块,如下所示:

require('server/server/app.js')
Run Code Online (Sandbox Code Playgroud)

Node.js然后尝试在下面的某处找到它node_modules.但我想,该文件不是依赖项,而是您自己代码的一部分.通常,你会这样需要它(考虑开头的点):

require('./server/server/app.js')
Run Code Online (Sandbox Code Playgroud)

这使得Node.js从当前目录('.')开始查找文件.

这将在具有以下文件夹结构的环境中工作:

/myfiles/main.js   <-- this file contains the `require` statement
/myfiles/server/
/myfiles/server/server/
/myfiles/server/server/app.js   <-- this file is being `require`d
Run Code Online (Sandbox Code Playgroud)