【问题标题】:Docker container fail to start NestJs appDocker 容器无法启动 NestJs 应用程序
【发布时间】:2020-05-18 12:27:28
【问题描述】:

我有 NestJs API 服务,当它使用“npm run dev”命令运行时,它运行得非常好。但是当我 dockerized 时,它无法运行该应用程序。我也使用容器尝试了节点版本 9,10 和 12。但它使用 run dev 命令在我的计算机中使用节点版本 9 顺利运行。 我正在使用docker run -it -p 9000:3001 dev-service 来运行容器。错误如下。

 nestjs-sample-api@1.0.0 start /app
> node index.js "prod"

TypeError: Cannot read property 'constructor' of undefined
    at Object.<anonymous> (/app/node_modules/cli-highlight/src/theme.ts:4:26)
    at Module._compile (internal/modules/cjs/loader.js:654:30)
    at Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Object.require.extensions.(anonymous function) [as .js] (/app/node_modules/ts-node/src/index.ts:406:14)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
    at Function.Module._load (internal/modules/cjs/loader.js:498:3)
    at Module.require (internal/modules/cjs/loader.js:598:17)
    at require (internal/modules/cjs/helpers.js:11:18)
    at Object.<anonymous> (/app/node_modules/cli-highlight/src/index.ts:3:1)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nestjs-sample-api@1.0.0 start: `node index.js "prod"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the nestjs-sample-api@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-05-15T03_20_53_617Z-debug.log

Docker 文件:

ROM node:9
WORKDIR /app
COPY package.json /app
COPY ormconfig.json /app
RUN npm install
COPY . /app
COPY ormconfig.json /dist/

CMD ["npm", "start", "prod" ]

【问题讨论】:

标签: docker devops nestjs docker-container


【解决方案1】:

我通过安装粉笔库解决了这个问题。发生这种情况是因为承包商正在寻找粉笔并且它没有安装在节点模块中。但这仅在我通过 docker 运行时引起。无论如何,在我将粉笔放入依赖项后它就可以工作了。

【讨论】:

    猜你喜欢
    • 2020-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-17
    • 1970-01-01
    • 2017-12-28
    相关资源
    最近更新 更多