部署到 Cloud Foundry 的应用无法启动

App deployed to Cloud Foundry fails to start

我尝试将我的 Node.js 应用程序部署到 Bluemix,但它失败了。

当我 运行 cf logs IssueTracker --recent 我看到这个错误:

   2018-12-10T16:50:24.38+0000 [APP/PROC/WEB/0] ERR module.js:549
   2018-12-10T16:50:24.38+0000 [APP/PROC/WEB/0] ERR     throw err;
   2018-12-10T16:50:24.38+0000 [APP/PROC/WEB/0] ERR     ^
   2018-12-10T16:50:24.38+0000 [APP/PROC/WEB/0] ERR Error: Cannot find module 'webpack'
   2018-12-10T16:50:24.38+0000 [APP/PROC/WEB/0] ERR     at Function.Module._resolveFilename (module.js:547:15)
   2018-12-10T16:50:24.38+0000 [APP/PROC/WEB/0] ERR     at Function.Module._load (module.js:474:25)
   2018-12-10T16:50:24.38+0000 [APP/PROC/WEB/0] ERR     at Module.require (module.js:596:17)
   2018-12-10T16:50:24.38+0000 [APP/PROC/WEB/0] ERR     at require (internal/module.js:11:18)
   2018-12-10T16:50:24.38+0000 [APP/PROC/WEB/0] ERR     at Object.<anonymous> (/home/vcap/app/dist/server.generated.js:1:6915)
   2018-12-10T16:50:24.38+0000 [APP/PROC/WEB/0] ERR     at r (/home/vcap/app/dist/server.generated.js:1:186)
   2018-12-10T16:50:24.38+0000 [APP/PROC/WEB/0] ERR     at Object.<anonymous> (/home/vcap/app/dist/server.generated.js:1:11679)
   2018-12-10T16:50:24.38+0000 [APP/PROC/WEB/0] ERR     at Object.<anonymous> (/home/vcap/app/dist/server.generated.js:1:12243)
   2018-12-10T16:50:24.38+0000 [APP/PROC/WEB/0] ERR     at r (/home/vcap/app/dist/server.generated.js:1:186)
   2018-12-10T16:50:24.38+0000 [APP/PROC/WEB/0] ERR     at Object.<anonymous> (/home/vcap/app/dist/server.generated.js:1:71669)
   2018-12-10T16:50:24.38+0000 [APP/PROC/WEB/0] ERR     at Object.<anonymous> (/home/vcap/app/dist/server.generated.js:1:73288)
   2018-12-10T16:50:24.38+0000 [APP/PROC/WEB/0] ERR     at r (/home/vcap/app/dist/server.generated.js:1:186)
   2018-12-10T16:50:24.38+0000 [APP/PROC/WEB/0] ERR     at Object.<anonymous> (/home/vcap/app/dist/server.generated.js:1:73356)
   2018-12-10T16:50:24.38+0000 [APP/PROC/WEB/0] ERR     at r (/home/vcap/app/dist/server.generated.js:1:186)
   2018-12-10T16:50:24.38+0000 [APP/PROC/WEB/0] ERR     at Object.<anonymous> (/home/vcap/app/dist/server.generated.js:1:73750)
   2018-12-10T16:50:24.38+0000 [APP/PROC/WEB/0] ERR     at r (/home/vcap/app/dist/server.generated.js:1:186)
   2018-12-10T16:50:24.43+0000 [APP/PROC/WEB/0] ERR npm ERR! code ELIFECYCLE
   2018-12-10T16:50:24.43+0000 [APP/PROC/WEB/0] ERR npm ERR! errno 1
   2018-12-10T16:50:24.43+0000 [APP/PROC/WEB/0] ERR npm ERR! issue-tracker-pc@1.0.0 start: `NODE_ENV=production node ./dist/server.generated.js`
   2018-12-10T16:50:24.43+0000 [APP/PROC/WEB/0] ERR npm ERR! Exit status 1
   2018-12-10T16:50:24.43+0000 [APP/PROC/WEB/0] ERR npm ERR! 
   2018-12-10T16:50:24.43+0000 [APP/PROC/WEB/0] ERR npm ERR! Failed at the issue-tracker-pc@1.0.0 start script.
   2018-12-10T16:50:24.43+0000 [APP/PROC/WEB/0] ERR npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
   2018-12-10T16:50:24.45+0000 [APP/PROC/WEB/0] ERR npm ERR! A complete log of this run can be found in:
   2018-12-10T16:50:24.45+0000 [APP/PROC/WEB/0] ERR npm ERR!     /home/vcap/app/.npm/_logs/2018-12-10T16_50_24_438Z-debug.log

我是 Cloud Foundry 的新手,所以不确定下一步该做什么。我该如何解决?

您的应用中似乎缺少依赖项:Error: Cannot find module 'webpack'

CF 运行 启动您的应用程序的命令是 NODE_ENV=production node ./dist/server.generated.js。在本地尝试 运行ning 看看是否可以重现。

您可能还想在干净的 VM 上尝试 运行ning,以排除缺少的依赖项已全局安装在您的开发人员工作站上的情况。当您的应用 运行 在 CF 上时,全局安装的依赖项将不可用。唯一可用的是 NPM/Yarn 根据您的 package.json 文件安装的内容。

希望对您有所帮助!

在我的例子中 package.json 输入错误。 请交叉验证