Home » vue » npm – module not found if run with docker

npm – module not found if run with docker

Posted by: admin November 26, 2021 Leave a comment

Questions:

I’m trying to run my vue application with docker. After updating npm packages locally, I get the following error:

-  Building for production...
 ERROR  Failed to compile with 1 error8:17:57 AM

This relative module was not found:

* ../internals/a-function in ./node_modules/core-js/internals/new-promise-capability.js
 ERROR  Build failed with errors.

Under Windows, everything works fine. I already tried to add the latest core-js module and to restore the package.json to a stable state, but without success. I don’t know what I am missing.

My Dockerfile:

# develop stage
FROM node:lts-alpine as develop-stage
WORKDIR /app
COPY app/package*.json ./
RUN npm install
COPY app/. .

# build stage
FROM develop-stage as build-stage
RUN npm run build

# production stage
FROM nginx:alpine as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html
EXPOSE 90
CMD ["nginx", "-g", "daemon off;"]

My package.json:

{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^1.2.36",
    "@fortawesome/free-solid-svg-icons": "^5.15.4",
    "@fortawesome/vue-fontawesome": "^2.0.6",
    "@growthbunker/vuedarkmode": "^0.5.56",
    "axios": "^0.21.4",
    "colormap": "^2.3.2",
    "core-js": "^3.18.2",
    "json-loader": "^0.5.7",
    "numeral": "^2.0.6",
    "prismjs": "^1.25.0",
    "pvw-visualizer": "^3.2.2",
    "splitpanes": "^2.3.8",
    "vue": "^2.6.11",
    "vue-json-editor": "^1.4.3",
    "vue-json-pretty": "^1.8.1",
    "vue-numeral-filter": "^2.0.0",
    "vue-numerals": "^4.0.6",
    "vue-plotly": "^1.1.0",
    "vue-prism-editor": "^1.3.0",
    "vue-remote-component": "^1.4.0",
    "vue-vtk-js": "^1.1.6",
    "vuescroll": "^4.17.3",
    "vuetify": "^2.5.10",
    "yaml-loader": "^0.6.0"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^4.5.14",
    "@vue/cli-plugin-eslint": "^4.5.14",
    "@vue/cli-service": "^4.5.14",
    "babel-eslint": "^10.1.0",
    "eslint": "^6.8.0",
    "eslint-plugin-html": "^6.2.0",
    "eslint-plugin-vue": "^7.19.1",
    "sass": "~1.32.0",
    "sass-loader": "^10.0.0",
    "vue-cli-plugin-vuetify": "^2.4.3",
    "vue-template-compiler": "^2.6.11",
    "vuetify-loader": "^1.7.3"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended"
    ],
    "parserOptions": {
      "parser": "babel-eslint"
    },
    "rules": {}
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not dead"
  ]
}
Answers:

Removing the build stage, somehow fixed it:

# develop stage
FROM node:lts-alpine as develop-stage
WORKDIR /app
COPY app/package*.json ./
RUN npm install
COPY app/. .

# # build stage
# FROM develop-stage as build-stage
RUN npm run build

# production stage
FROM nginx:alpine as production-stage
COPY --from=develop-stage /app/dist /usr/share/nginx/html
EXPOSE 90
CMD ["nginx", "-g", "daemon off;"]