1

this is my first question on stackoverflow. Thank you all for this absolute fantastic forum!

I try to get a vue pwa in docker running. I used the vue-cli to setup the pwa application. Installing and running local is no problem.

Then i tried to dockerize the project. I tried with following docker code:

# Start with a Node.js image.
FROM node:10

# Make directory to install npm packages
RUN mkdir /install

ADD ["./code/package.json", "/install"]
WORKDIR /install

RUN npm install --verbose

ENV NODE_PATH=/install

# Copy all our files into the image.
RUN mkdir /code
WORKDIR /code
COPY . /code/

EXPOSE 8080
CMD npm run dev

The problem is when starting up the composition i get the error:

web_1        | internal/modules/cjs/loader.js:573
web_1        |     throw err;
web_1        |     ^
web_1        | 
web_1        | Error: Cannot find module 'chalk'
...

I tried different ways now for a few days. But i can't see any solution. Do i miss something? Is there an incompatibility?

I also tried to change completely to yarn but the effect is the same. So i don't think there is a problem with installing the packages. Could there be a problem with the Node_Path variable?

Thanks for your support in advance!

B.S.
  • 53
  • 1
  • 7
  • I don't think I have the solution for your problem, so see this just as a tip: the `--dev` flag is deprecated in the current npm version (maybe check your version if you don't get a warning); actually you don't want to _only_ `npm install` dev packages -- you want to install _all_ packages while developing. P.S.: a well written first question :-) – dr_barto May 30 '18 at 12:12
  • Thanks. I edited the file. As expected there is no difference. Now it should follow the latest rules. – B.S. May 30 '18 at 14:06
  • Possible duplicate of [npm install won't install devDependencies](https://stackoverflow.com/questions/34700610/npm-install-wont-install-devdependencies) – Max Liashuk May 31 '18 at 22:05
  • I don't think there is a relation. As only the 'chalk' module seems to make problems. Other packages from the devDependencies are installed correctly. – B.S. Jun 01 '18 at 06:18

1 Answers1

1

Facing the same issue,

Normally you wouldn't install any devDependencies for production, therefore when NODE_ENV=production, NPM/Yarn will not install devDependencies.

For docker use case, when we build static site within the docker contianer, we might need to use NODE_ENV = production, to replace some PRODUCTION VARIABLES, therefore we'll need to use NODE_ENV = production but also install dev dependencies.

Some of the solution

1 - move everything from devDependencies to dependencies

2 - do not set NODE_ENV=production at yarn install || npm install, only set it after module installation

3 - for YARN, NODE_ENV=production yarn install --production=false, there should be NPM equivalent

4 - ( not tested ), some other name I.E NODE_ENV=prod, instead of the full name production, but you might need to play around with other configs that relies on NODE_ENV=production

devric
  • 3,555
  • 4
  • 22
  • 36