1

I'm trying to perform a Docker node/ts project. I don't want dev dependencies, for obvious reasons.

When I run npm --production install or npm install --omit-dev or npm --production install --omit-dev, and/or set NODE_ENV=production in the Dockerfile, npm is still trying to install prettier which is in my dev deps.

I have tried all options I could think of; docker system prune, running the docker build with --no-cache, and even changing the base image in the Dockerfile to "trick" docker into using no cache. Believe me, docker is not caching anything.

What could be happening here? I'm totally at a loss and using --verbose in the npm install doesn't add anything useful.

The answers in this question don't work, including the --no-optional flag.

The Dockerfile (no .dockerignore used):

FROM node:16 ENV NODE_ENV=production # -- Setup -- RUN mkdir -p /app/ WORKDIR /app/ # -- Install -- RUN npm update ADD package.json /app/ RUN npm install --omit-dev --verbose # -- Copy in source -- COPY .env /app/ COPY src /app/src ## -- Start app -- CMD ["node", "./src/my_app.js"] 

p.s. I know I could use something other than npm, but I would prefer to stick with the default option, if I can.


p.p.s Can work around this issue by simply removing the devDependencies section from my package.json

6
  • 1
    Does this answer your question? How do you prevent install of "devDependencies" NPM modules for Node.js (package.json)? Commented Aug 22, 2023 at 9:33
  • 1
    Try Max's comment, and NODE_ENV=production npm install or prod instead of production. Commented Aug 22, 2023 at 9:35
  • 1
    If this is in a Docker context, can you edit the question to include the Dockerfile? I've seen several multi-stage Dockerfiles go by that don't effectively manage the node_modules tree. It's also worth double-checking that you have a .dockerignore file that omits the host's node_modules directory from the build context. Commented Aug 22, 2023 at 9:51
  • Thanks @Anuga, updated post to reflect that I tried this. Commented Aug 22, 2023 at 9:51
  • 1
    @goldfishalpha Can you share your Dockerfile? Commented Aug 22, 2023 at 10:00

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.