node.js - Custom scripts don't work on nodejs docker container, missing script (throw err, npm ERR!) - Stack Overflow

Trying to up nodejs with custom scripts, but every time it fails with error (on Linux VM, on Windows it

Trying to up nodejs with custom scripts, but every time it fails with error (on Linux VM, on Windows it works with the same configuration):

Attaching to app-nodejs
app-nodejs  | npm ERR! Missing script: "start:prod"
app-nodejs  | npm ERR! 
app-nodejs  | npm ERR! To see a list of scripts, run:
app-nodejs  | npm ERR!   npm run

npm run showed (from debug part of Dockerfile):

#13 0.318 Lifecycle scripts included in [email protected]:
#13 0.318   start
#13 0.318     nest start
#13 0.318   test
#13 0.318     jest
#13 0.318 
#13 0.318 available via `npm run-script`:
#13 0.318   build
#13 0.318     nest build
#13 0.318   format
#13 0.318     prettier --write "src/**/*.ts" "test/**/*.ts"
#13 0.318   start:dev
#13 0.318     nest start --watch
#13 0.318   start:debug
#13 0.318     nest start --debug --watch
#13 0.318   start:prod
#13 0.318     node dist/main.js

RUN ls -la dist showed (from debug part of Dockerfile):

...
-rwxr-xr-x 1 root root   11 Nov 19 19:53 main.d.ts
-rwxr-xr-x 1 root root  466 Nov 19 19:53 main.js
-rwxr-xr-x 1 root root  419 Nov 19 19:53 main.js.map
...

Tried to change ENTRYPOINT ["npm", "run", "start:prod"] to ENTRYPOINT ["node", "dist/main.js"], it fails with an error Error: Cannot find module '/usr/src/app/dist/main.js'

Added this to tsconfig.json:

"outDir": "./dist",
"rootDir": "./src",

Checked and changed rights on VM (+x)

Absolutely can't understand what's wrong because I can run the same project on Windows (in docker also) without any problems and errors.

Here's Dockerfile

FROM node:16.20.2

RUN apt-get update && apt-get install -y bash postgresql-client

WORKDIR /usr/src/app
COPY package*.json ./

RUN npm install

COPY . .
RUN chmod -R 755 /usr/src/app && npm run build

RUN chmod -R 755 /usr/src/app/dist && ls -la dist

RUN npm run && node -v && npm -v

EXPOSE 3000

ENTRYPOINT ["npm", "run", "start:prod"]

Container starts with docker-compose up --build --force-recreate, only folders src and test added to volumes, all changes in any config file triggers rebuild, so they don't include to volumes.

!!! One of the comments helped me resolve this problem. I changed ENTRYPOINT ["npm", "run", "start:prod"] to ENTRYPOINT ["npm", "run-script", "start:prod"] and added to Dockerfile:

COPY *.json ./
COPY *.js ./
COPY ./src ./src
COPY ./test ./test

Instead of COPY . ..

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742379740a4432890.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信