node.js - 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"
]
}
解决方案
删除构建阶段,以某种方式修复它:
# 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;"]
推荐阅读
- filter - wireshark:使用过滤器将数据从转储转换为文本文件
- android - 使用 gradle 错误构建 Android 项目失败:“非法嵌入符号字符”
- yocto - 将 python 内部模块(cgi.py)添加到 yocto 图像
- c# - 如果存在则删除子字符串
- java - 哪个 jar 有 ACWrapper 类
- bash - 如何对选项卡文件中的每一列进行累积和连续求和(UNIX 环境)
- sql - 要在 informatica 源限定符转换中使用的递归 DB2 Sql 查询
- arduino - Arduino:如何逐行读取 SD 卡文本文件
- c# - 第一次成功运行后 Windows 服务自动停止
- opencv - 如何从具有大量细节的图像中指定计算机感兴趣的区域?