Nuxt,js&Docker如何通过Docker来实现我的Nuxt项目?我的代码正在运行,但有错误

问题描述 投票:0回答:1

我的docker文件:

FROM node:11.13.0-alpine

# create destination directory
RUN mkdir -p /Users/traian/Desktop/Projects/jackpot-frontend
WORKDIR /Users/traian/Desktop/Projects/jackpot-frontend

# copy the app, note .dockerignore
COPY . /Users/traian/Desktop/Projects/jackpot-frontend/
RUN npm install

# build necessary, even if no static files are needed,
# since it builds the server as well
RUN npm run build

# expose 5000 on container
EXPOSE 3000

# set app serving to permissive / assigned
ENV NUXT_HOST=0.0.0.0
# set app port
ENV NUXT_PORT=3000

# start the app
CMD [ "npm", "start" ]

运行:docker build -t my_app。

还有我的错误:


Step 5/10 : RUN npm install
 ---> Running in 69625d2b465c
npm WARN [email protected] requires a peer of eslint@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of eslint@^5.0.0 but none is installed. You must install peer dependencies yourself.

audited 11365 packages in 9.648s
found 1 critical severity vulnerability
  run `npm audit fix` to fix them, or `npm audit` for details
Removing intermediate container 69625d2b465c
 ---> 82db717aa5a4
Step 6/10 : RUN npm run build
 ---> Running in 7eead80fead7

> [email protected] build /Users/traian/Desktop/Projects/jackpot-frontend
> nuxt build

ℹ Production build
✔ Builder initialized
✔ Nuxt files generated
ℹ Compiling Client
✔ Client: Compiled with some errors in 16.49s

Hash: 97bf23961433d64dbf80
Version: webpack 4.39.2
Time: 16462ms
Built at: 08/26/2019 6:45:29 AM
                  Asset       Size  Chunks  Chunk Names
016dd6896a62bff82ea6.js   2.52 KiB      12  runtime
127f1d7e26d32b448914.js   1.37 KiB      11  pages/tennis/index
1c6974e86086860ebc8a.js  198 bytes       1  lang-ro-RO
27ea0f5218a55290c799.js   1.76 KiB       6  pages/football/_id/index
38203ff7207cdd968b92.js   18.1 KiB       9  pages/index
3dbfb5f2cdee14257f07.js  194 bytes       0  lang-en-US
3fa01f93cfa9081d45ca.js    177 KiB       4  commons.app
86b5517e6739eb6ab791.js   1.37 KiB       8  pages/hockey/index
98f463f2c8e87f6fbd10.js    486 KiB       3  app
               LICENSES  994 bytes          
aceafdea5e77a1633a17.js   1.37 KiB       7  pages/golf/index
b1cbc49b5fef9c66470d.js    288 KiB      13  vendors.app
ddcbea6cf5d83bb9d6ec.js   1.37 KiB       5  pages/basketball/index
dfd8dfc499ca635fd6fb.js   1.54 KiB      10  pages/tennis/_id/index
e2f30ff0dcc874e9b4a7.js   67.9 KiB       2  pages/football/_id/index.pages/index
      fonts/674f50d.eot    162 KiB          
    fonts/af7ae50.woff2   75.4 KiB          
      fonts/b06871f.ttf    162 KiB          
     fonts/fee66e7.woff   95.7 KiB          
        img/912ec66.svg    434 KiB          
Entrypoint app = 016dd6896a62bff82ea6.js 3fa01f93cfa9081d45ca.js b1cbc49b5fef9c66470d.js 98f463f2c8e87f6fbd10.js

ERROR in ./plugins/calendar/vueDatePick.vue?vue&type=style&index=0&lang=scss& (./node_modules/css-loader/dist/cjs.js??ref--9-oneOf-1-1!./node_modules/vue-loader/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/src??ref--9-oneOf-1-2!./node_modules/sass-loader/lib/loader.js??ref--9-oneOf-1-3!./node_modules/vue-loader/lib??vue-loader-options!./plugins/calendar/vueDatePick.vue?vue&type=style&index=0&lang=scss&)
Module build failed (from ./node_modules/sass-loader/lib/loader.js):
Error: Missing binding /Users/traian/Desktop/Projects/jackpot-frontend/node_modules/node-sass/vendor/linux-x64-64/binding.node
Node Sass could not find a binding for your current environment: Linux 64-bit with Node.js 10.x

我不知道为什么,如果我跑步:

npm构建

npm运行生产

工作中

或npm run dev

工作中

但是如果我使用Docker构建,则会收到此问题((]

如果此代码发布在服务器上并且正在运行,则如果运行npm run dev会遇到相同的问题

MacOS,节点v10.16.2

我的docker文件:FROM节点:11.13.0-alpine#创建目标目录RUN mkdir -p / Users / traian / Desktop / Projects / jackpot-frontend WORKDIR / Users / traian / Desktop / Projects / jackpot-frontend#copy。 ..

javascript docker build project nuxt
1个回答
0
投票

您应该打开您的package.json文件,并查看两个软件包“ sass-loader”和“ node-sass”的附加位置,如果在devDependencies中,这将是一个答案。为什么会这样?发生这种情况的原因是,您在docker默认情况下使用NODE_ENV = production在docker中运行您的nuxt应用,并且未在生产模式下安装devDependencies。

© www.soinside.com 2019 - 2024. All rights reserved.