首页 > 解决方案 > npm - 如果使用 docker 运行,则找不到模块

问题描述

我正在尝试使用 docker 运行我的 vue 应用程序。在本地更新 npm 包后,我收到以下错误:

-  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.

在 Windows 下,一切正常。我已经尝试添加最新的 core-js 模块并将 package.json 恢复到稳定状态,但没有成功。我不知道我错过了什么。

我的 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;"]

我的 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"
  ]
}

标签: node.jsdockervue.jsnpm

解决方案


删除构建阶段,以某种方式修复它:

# 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;"]

推荐阅读