樓主這幾天想用docker里運行一個vue應用,網上下載下來的是用yarn build進行發布的。但是每次Dockerfile執行到yarn build命令時都報同一個錯誤。
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'semver'
覺得很奇怪,并且在Dockerfile中install semver還是同樣問題。查閱了網上資料,說這個模塊應該時nodejs自帶的。那么docker中的nodejs為什么沒有這個模塊呢。
貼上Dockerfile檔案
FROM node:10.16.3
# 如果你在國內,這行配置很有必要,不然打包會非常非常慢,原因嘛,都懂。
RUN npm config set registry https://registry.npm.taobao.org
# install simple http server for serving static content
RUN npm install -g http-server
# make the 'app' folder the current working directory
WORKDIR /app
# copy both 'package.json' and 'package-lock.json' (if available)
COPY package*.json ./
# install project dependencies
RUN yarn install
# copy project files and folders to the current working directory (i.e. 'app' folder)
COPY . .
# build app for production with minification
RUN yarn build
EXPOSE 8080
# 加入埠自定義配置,避免與其他K8S容器埠沖突
CMD [ "http-server","-p","8080", "dist" ]
uj5u.com熱心網友回復:
你這情況估計是沒有默認安裝包里面沒有,找個編譯版的自己編譯一下吧,打成tar包,在再dockerfile里面直接ADD加進環境應該就行。uj5u.com熱心網友回復:
感謝回復,我去試一下
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/25777.html
標籤:Docker
