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

goldfishalpha
  • 447
  • 2
  • 4
  • 13
  • 1
    Does this answer your question? [How do you prevent install of "devDependencies" NPM modules for Node.js (package.json)?](https://stackoverflow.com/questions/9268259/how-do-you-prevent-install-of-devdependencies-npm-modules-for-node-js-package) – Max Aug 22 '23 at 09:33
  • 1
    Try Max's comment, and `NODE_ENV=production npm install` or `prod` instead of `production`. – Anuga Aug 22 '23 at 09: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. – David Maze Aug 22 '23 at 09:51
  • Thanks @Anuga, updated post to reflect that I tried this. – goldfishalpha Aug 22 '23 at 09:51
  • 1
    @goldfishalpha Can you share your `Dockerfile`? – Robin Thomas Aug 22 '23 at 10:00
  • @DavidMaze Question updated. – goldfishalpha Aug 22 '23 at 10:02
  • Also add: the dep/devDep/optionalDep part och the package.json (if you can). Pretty sure, omit is run like this: `--omit dev --omit optional` etc. Also provide the parts you can, of the output of `RUN npm install --omit-dev --verbose`. Setting the env of node should be enough for npm to not install the deps. – Anuga Aug 22 '23 at 14:27

0 Answers0