How do I figure out what dependency is missing in

2019-06-02 20:51发布

问题:

I am trying to deploy my Node.js project to OpenShift and I get 503 when trying to view the site.

I am aware from research that this indicates a problem with my webserver project. By checking the logs, I have determined that this appears to be an issue of a missing dependency. However, the logs don't appear to tell me which one:

module.js:340
    throw err;
          ^
Error: Cannot find module '/var/lib/openshift/551c63f85973ca05430002b8/app-root/runtime/repo/server.js'

I have verified that every package which is "required" by my webserver is present in both the package.json file and is present in the node_modules folder.

{
  "name": "NekoList",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www"
  },
  "dependencies": {
    "bcrypt-nodejs": "0.0.3",
    "body-parser": "~1.12.4",
    "cookie-parser": "~1.3.5",
    "debug": "~2.2.0",
    "ejs": "~2.3.1",
    "express": "~4.12.4",
    "mongoose": "^4.0.3",
    "morgan": "~1.5.3",
    "node-gyp": "^2.0.1",
    "secure-random": "^1.1.1",
    "serve-favicon": "~2.2.1"
  }
}

When running an npm install or npm update I get no errors. I do get warnings about an unmet dependency on debug ~2.2.0, but I have this same warning in another project and it doesn't cause a critical failure. I have no code that uses this module. It's just there because it was part of the template.

minimist@0.0.8 node_modules/node-gyp/node_modules/mkdirp/node_modules/minimist
npm WARN unmet dependency /var/lib/openshift/551c63f85973ca05430002b8/app-root/runtime/repo/node_modules/express/node_modules/finalhandler requires debug@'~2.2.0' but will load
npm WARN unmet dependency undefined,
npm WARN unmet dependency which is version undefined

Also, the project runs fine on my local development environment using the Webstorm built-in server.

I am looking to know what I might do to fix, or at least shed some light on the root of the issue.

Thanks in advance.

[Edit] So, based on what Saba Hassan is saying, it looks like node is trying to run the nonexistant file server.js, instead of the entry point that I have defined, bin/www

So, I added a file called server.js with the basic example server. Openshift still cannot find the file. Same error message. [/Edit]

[Solution] I have concluded that the basic assumption of this question is incorrect. I endorsed an answer that explains why OpenShift is looking in the wrong place for the insertion point. However, I started this thread to figure out why I was getting a missing dependency error. Even after implementing the solution below, I still got the same error message, about missing a dependency.

The explanation is this:

For some reason, any problem with the insertion point file, or any file that it requires will throw back an error saying that the insertion point file module is missing.

I had some variable in one file that wasn't configured right for OpenShift and the most helpful error message contained in the OpenShift logs was that the root module was missing.

Conclusion "missing dependency" errors might just mean that you have some kind of logic error, somewhere in your entire project. [/Solution]

回答1:

You are using the "scripts" property, but on OpenShift you really should use "main" instead. This is because OpenShift uses node-supervisor to start and manage your Node.js application. It looks like if you don't supply a "main" it defaults to server.js



回答2:

I think you are running node server.js command from wrong directory. Navigate to the directory where server.js file exists and then run the command.