简体   繁体   English

Docker中的Nuxt.js:缺少依赖项

[英]Nuxt.js in Docker: missing dependencies

I am trying to run a Nuxt.js application in Docker. 我正在尝试在Docker中运行Nuxt.js应用程序。 I've setup my Dockerfile like this: 我已经像这样设置了Dockerfile:

FROM node:10.15.1 as base
WORKDIR /usr/src/app
COPY package.json ./
ENV HOST 0.0.0.0

FROM base as development
RUN npm install
COPY . .
ENV NODE_ENV development
EXPOSE 3000
CMD [ "npm", "run", "dev" ]

And my docker-compose.yml: 和我的docker-compose.yml:

version: "3.7"
services:
  frontend:
    container_name: frontend
    restart: unless-stopped
    build:
      context: .
      target: development
    volumes:
      - .:/usr/src/app
      - /usr/src/app/node_modules
    ports:
      - "3000:3000"

when I run docker-compose up I am getting 当我运行docker-compose up

frontend    | These dependencies were not found:                    friendly-errors 10:52:33
frontend    |                                                       friendly-errors 10:52:33
frontend    | * core-js/modules/es6.array.find in ./.nuxt/client.js friendly-errors 10:52:33
frontend    | * core-js/modules/es6.array.iterator in ./.nuxt/client.js
frontend    | * core-js/modules/es6.date.to-string in ./.nuxt/utils.js
frontend    | * core-js/modules/es6.function.name in ./.nuxt/client.js
frontend    | * core-js/modules/es6.object.assign in ./.nuxt/client.js
frontend    | * core-js/modules/es6.object.keys in ./.nuxt/utils.js friendly-errors 10:52:33
frontend    | * core-js/modules/es6.promise in ./.nuxt/client.js    friendly-errors 10:52:33
frontend    | * core-js/modules/es6.regexp.constructor in ./.nuxt/utils.js
frontend    | * core-js/modules/es6.regexp.match in ./.nuxt/client.js
frontend    | * core-js/modules/es6.regexp.replace in ./.nuxt/middleware.js
frontend    | * core-js/modules/es6.regexp.search in ./.nuxt/utils.js
frontend    | * core-js/modules/es6.regexp.split in ./.nuxt/utils.js
frontend    | * core-js/modules/es6.regexp.to-string in ./.nuxt/utils.js
frontend    | * core-js/modules/es6.string.includes in ./.nuxt/client.js, ./.nuxt/components/nuxt-link.client.js
frontend    | * core-js/modules/es6.string.iterator in ./.nuxt/utils.js
frontend    | * core-js/modules/es6.string.repeat in ./.nuxt/utils.js
frontend    | * core-js/modules/es6.string.starts-with in ./.nuxt/utils.js
frontend    | * core-js/modules/es6.symbol in ./.nuxt/middleware.js, ./.nuxt/components/nuxt-link.client.js
frontend    | * core-js/modules/es7.array.includes in ./.nuxt/client.js, ./.nuxt/components/nuxt-link.client.js
frontend    | * core-js/modules/es7.promise.finally in ./.nuxt/client.js
frontend    | * core-js/modules/es7.symbol.async-iterator in ./.nuxt/client.js, ./.nuxt/components/nuxt-link.client.js
frontend    | * core-js/modules/web.dom.iterable in ./.nuxt/client.js, ./.nuxt/components/nuxt-link.client.js
frontend    |                                                       friendly-errors 10:52:33
frontend    | To install them, you can run: npm install --save core-js/modules/es6.array.find core-js/modules/es6.array.iterator core-js/modules/es6.date.to-string core-js/modules/es6.function.name core-js/modules/es6.object.assign core-js/modules/es6.object.keys core-js/modules/es6.promise core-js/modules/es6.regexp.constructor core-js/modules/es6.regexp.match core-js/modules/es6.regexp.replace core-js/modules/es6.regexp.search core-js/modules/es6.regexp.split core-js/modules/es6.regexp.to-string core-js/modules/es6.string.includes core-js/modules/es6.string.iterator core-js/modules/es6.string.repeat core-js/modules/es6.string.starts-with core-js/modules/es6.symbol core-js/modules/es7.array.includes core-js/modules/es7.promise.finally core-js/modules/es7.symbol.async-iterator core-js/modules/web.dom.iterable
frontend    | ℹ Waiting for file changes                                            10:52:33
frontend    |
frontend    |  READY  Server listening on http://0.0.0.0:3000                       10:52:33
frontend    |

My project works fine when used without docker, also I am using almost the same Dockerfile for another Vue project (not Nuxt). 我的项目在没有docker的情况下可以正常工作,另外我在另一个Vue项目(不是Nuxt)中使用几乎相同的Dockerfile。 After some research I found a solution to add @babel/polyfill to my dependencies. 经过研究,我找到了一种解决方案,可以将@babel/polyfill添加到我的依赖项中。 But when I do so it complains about the next missing dependency, so I guess all dependencies that are installed by Nuxt are missing. 但是,当我这样做时,它会抱怨下一个缺少的依赖项,因此我猜想Nuxt安装的所有依赖项都丢失了。 Also this doesn't explain why it runs without Docker. 这也不能解释为什么它在没有Docker的情况下运行。

When I run docker-compose run sh to get into the shell and then ls -lah to list all files: 当我运行docker-compose run sh进入外壳,然后使用ls -lah列出所有文件:

-rw-r--r--   1 root root   32 Feb  1 13:48 .dockerignore
-rw-r--r--   1 root root 1.1K Feb  1 13:23 .eslintrc.js
drwxr-xr-x  10 root root  320 Feb  2 09:17 .git
-rw-r--r--   1 root root 1.2K Feb  1 13:01 .gitignore
drwxr-xr-x  14 root root  448 Feb  2 10:52 .nuxt
-rw-r--r--   1 root root  334 Feb  2 10:51 Dockerfile
-rw-r--r--   1 root root  370 Feb  1 13:01 README.md
drwxr-xr-x   3 root root   96 Feb  1 13:01 assets
drwxr-xr-x   4 root root  128 Feb  1 13:01 components
drwxr-xr-x   4 root root  128 Feb  1 13:01 layouts
drwxr-xr-x   3 root root   96 Feb  1 13:01 middleware
drwxr-xr-x 798 root root  32K Feb  2 10:56 node_modules
-rw-r--r--   1 root root 1.7K Feb  1 13:45 nuxt.config.js
-rw-r--r--   1 root root 363K Feb  1 13:19 package-lock.json
-rw-r--r--   1 root root  612 Feb  2 10:06 package.json
drwxr-xr-x   4 root root  128 Feb  1 13:01 pages
drwxr-xr-x   4 root root  128 Feb  1 13:01 plugins
drwxr-xr-x   3 root root   96 Feb  1 13:01 server
drwxr-xr-x   4 root root  128 Feb  1 13:01 static
drwxr-xr-x   3 root root   96 Feb  1 13:01 store

I see node_modules and .nuxt directories exist. 我看到存在node_modules.nuxt目录。 Also the core-js package is present within node_modules . 此外, node_modules还包含core-js包。

Any idea? 任何想法?

I had the same problem. 我有同样的问题。 I solved it with 我解决了

npm i core-js@2.6.5

I think there is a nuxt dependency that is using an old core-js version and this one produce this error. 我认为有一个nuxt依赖项正在使用旧的core-js版本,并且这会产生此错误。

I found this in my package-lock.json 我在我的package-lock.json中找到了这个

    "@nuxt/babel-preset-app": {
      "version": "2.5.1",
      "resolved": "https://registry.npmjs.org/@nuxt/babel-preset-app/-/babel-preset-app-2.5.1.tgz",
      "requires": {
        "@babel/core": "^7.4.0",
        "@babel/plugin-proposal-class-properties": "^7.4.0",
        "@babel/plugin-proposal-decorators": "^7.4.0",
        "@babel/plugin-syntax-dynamic-import": "^7.2.0",
        "@babel/plugin-transform-runtime": "^7.4.0",
        "@babel/preset-env": "^7.4.2",
        "@babel/runtime": "^7.4.2",
        "@vue/babel-preset-jsx": "^1.0.0-beta.2",
        "core-js": "^2.6.5"
      },
      "dependencies": {
        "core-js": {
          "version": "2.6.5",
          "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.5.tgz",
        }
      }
    },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM