vue pwa in docker - cannot find module 'chalk' - docker

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!

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

Related

Dockerizing Nuxt 3 app for development purposes

I'm trying to dockerize Nuxt 3 app, but I have strange issue.
This Dockerfile is working with this docker run command:
docker run -v /Users/my_name/developer/nuxt-app:/app -it -p 3000:3000 nuxt-app
# Dockerfile
FROM node:16-alpine3.14
# create destination directory
RUN mkdir -p /usr/src/nuxt-app
WORKDIR /usr/src/nuxt-app
# update and install dependency
RUN apk update && apk upgrade
RUN apk add git
# copy the app, note .dockerignore
COPY . /usr/src/nuxt-app/
RUN npm install
# RUN npm run build
EXPOSE 3000
# ENV NUXT_HOST=0.0.0.0
# ENV NUXT_PORT=3000
CMD [ "npm", "run", "dev"]
I don't understand why despite mounting it to /app folder in the container and declaring /usr/src/nuxt-app in Dockerfile it works.
When I try to match them then I get this error:
ERROR (node:18) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 3) 20:09:42
(Use `node --trace-warnings ...` to show where the warning was created)
✔ Nitro built in 571 ms nitro 20:09:43
ERROR [unhandledRejection]
You installed esbuild for another platform than the one you're currently using.
This won't work because esbuild is written with native code and needs to
install a platform-specific binary executable.
Specifically the "#esbuild/darwin-arm64" package is present but this platform
needs the "#esbuild/linux-arm64" package instead. People often get into this
situation by installing esbuild on Windows or macOS and copying "node_modules"
into a Docker image that runs Linux, or by copying "node_modules" between
Windows and WSL environments.
If you are installing with npm, you can try not copying the "node_modules"
directory when you copy the files over, and running "npm ci" or "npm install"
on the destination platform after the copy. Or you could consider using yarn
instead of npm which has built-in support for installing a package on multiple
platforms simultaneously.
If you are installing with yarn, you can try listing both this platform and the
other platform in your ".yarnrc.yml" file using the "supportedArchitectures"
feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
Keep in mind that this means multiple copies of esbuild will be present.
Another alternative is to use the "esbuild-wasm" package instead, which works
the same way on all platforms. But it comes with a heavy performance cost and
can sometimes be 10x slower than the "esbuild" package, so you may also not
want to do that.
at generateBinPath (node_modules/vite/node_modules/esbuild/lib/main.js:1841:17)
at esbuildCommandAndArgs (node_modules/vite/node_modules/esbuild/lib/main.js:1922:33)
at ensureServiceIsRunning (node_modules/vite/node_modules/esbuild/lib/main.js:2087:25)
at build (node_modules/vite/node_modules/esbuild/lib/main.js:1978:26)
at runOptimizeDeps (node_modules/vite/dist/node/chunks/dep-3007b26d.js:42941:26)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
I have absolutely no clue what is going on here except architecture mismatch (that doesn't seem to be the case with working version - I'm on MacBook Air M1).
The second issue is that mounting doesn't update the page.
Okay, found the way. The issue was with Vite because HMR module is using port 24678 and I didn't expose it so it couldn't reload the page. This is how it should be looking:
docker run --rm -it \
-v /path/to/your/app/locally:/usr/src/app \
-p 3000:3000 \
-p 24678:24678 \
nuxt-app
Dockerfile
FROM node:lts-slim
WORKDIR /usr/src/app
CMD ["sh", "-c", "npm install && npm run dev"]

You installed esbuild on another platform than the one you're currently using.This won't work because esbuild is written with native code and needs to

I am trying to containerise Svelte js app inside a docker container and I am getting this error on the log complaining about esbuild in a different platform , I am using M1 mac, I have tried to install esbuild-wasm as what the log suggested and tried npm i esbuild-linux-arm64 as a step in the docker file and tried RUN npm install yarn as the log suggested yarn as it have built-in stuff deal with the platform but it didn't work
my docker file
FROM node:16.10.0
WORKDIR /my-website
COPY package.json .
RUN npm install
# tried this earlier
# RUN npm install yarn
# RUN yarn install
# and this
#RUN npm i esbuild-wasm
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
the error is
rad-website_1 | You installed esbuild on another platform than the one you're currently using.
rad-website_1 | This won't work because esbuild is written with native code and needs to
rad-website_1 | install a platform-specific binary executable.
rad-website_1 |
rad-website_1 | Specifically the "esbuild-darwin-arm64" package is present but this platform
rad-website_1 | needs the "esbuild-linux-arm64" package instead. People often get into this
rad-website_1 | situation by installing esbuild on Windows or macOS and copying "node_modules"
rad-website_1 | into a Docker image that runs Linux, or by copying "node_modules" between
rad-website_1 | Windows and WSL environments.
You've copied node_modules from your local environment to the container. Locally you have packages for the darwin-arm64 arch, but inside the container, it is a Linux system that requires packages for linux-arm64.
To avoid such errors you should not copy node_modules to the container.
All you need is to add node_modules to .dockerignore file

Error installing Sharp in docker container

When running an npm install locally everything is fine but as soon as I try it inside my docker container I get the following error:
/api/node_modules/sharp/lib/constructor.js:1
Something went wrong installing the "sharp" module
Error relocating /api/node_modules/sharp/build/Release/../../vendor/8.10.6/lib/libvips-cpp.so.42: _ZNSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEEC1Ev: symbol not found
Any help greatly appreciated!
Docker image is incredibly simple:
FROM node:12.13.0-alpine AS alpine
WORKDIR /api
COPY package.json .
RUN npm install
In my case after trying a lot of different options from scouring the github issues for Sharp, the addition of this line to my Dockerfile fixed it:
RUN npm config set unsafe-perm true
In case you are using node:15 or later, --unsafe-perm was removed, this is a workaround:
...
RUN chown root.root . # make sure root own the directory before installing Sharp
RUN npm install

Query engine binary for current platform "debian-openssl-1.0.x" could not be found

I need help on Dockerize my Prisma + GraphQL, I have tried many more options and tricks to resolve this issue but can not able to make it work.
Seems like when I actually run the application without Dockerize application work perfectly like below
But after Dockerize the App, it shows me an error like below
Can anyone help me out with this, I can not able to publish or Dockerize the app in local environment?
Dockerfile
# pull the official base image
FROM node:10.11.0
# set your working directory
WORKDIR /api
# install application dependencies
COPY package*.json ./
RUN npm install --silent
RUN npm install -g #prisma/cli
# add app
COPY . ./
# will start app
CMD ["node", "src/index.js"]

Dokku/Docker deploying apps fails

Docker noob here so bear with me.
I have a VPS with dokku configured, it has multiple apps already running.
I am trying to add a fairly complex app at present. But docker just fails with the following error.
From what I understand I need to update the packages the error is given. Problem is they are needed by some other module and I cant update it. Is a way to make docker bypass the warning and build.
Following is the content of my docker
FROM mhart/alpine-node:6
# Create app dir
RUN mkdir -p /app
WORKDIR /app
# Install dependancy
COPY package.json /app
RUN npm install
# Bundle the app
COPY . /app
EXPOSE 9337
CMD ["npm", "start"]
Been trying this for a couple of days not with no success.
Any help greatly appreciated
Thanks.
I believe npm process get killed with error 137 on docker is usually caused by out of memory error. You can try adding swap file (or add more RAM) to test this.

Resources