Here are my files.
Here is I think the core of the problem.
Could not resolve dependency:
npm ERR! peer graphql#"^0.12.0 || ^0.13.0 || ^14.0.0" from graphql-middleware#4.0.2
docker-compose.yml
version: '3.7'
services:
apollo:
container_name: apollo
build:
context: .
dockerfile: Dockerfile
environment:
- NODE_ENV=development
volumes:
- '.:/app'
- '/app/node_modules'
ports:
- 4000:4000
restart: always
Dockerfile
# Use the official image as a parent image.
FROM node:current-slim
# Set the working directory.
WORKDIR /app
# Setting environment path.
ENV PATH=/app/node_modules/.bin:$PATH
# Copy the file from your host to your current location.
COPY package.json .
# Run the command inside your image filesystem.
RUN npm init --yes
RUN npm install --save cors apollo-server-express express graphql reflect-metadata type-graphql apollo-datasource-rest soap jsonwebtoken --yes
RUN npm install nodemon -g --yes
# Add metadata to the image to describe which port the container is listening on at runtime.
EXPOSE 4000
# Copy the rest of your app's source code from your host to your image filesystem.
COPY . .
CMD [ "nodemon", "index.js" ]
Dependency Error
$ docker-compose up --build
Building apollo
Step 1/10 : FROM node:current-slim
---> f3f62dfcc735
Step 2/10 : WORKDIR /app
---> Using cache
---> 33088e65c748
Step 3/10 : ENV PATH=/app/node_modules/.bin:$PATH
---> Using cache
---> c7f742267b26
Step 4/10 : COPY package.json .
---> Using cache
---> 76285ea4a8ca
Step 5/10 : RUN npm init --yes
---> Using cache
---> 29a3d715136b
Step 6/10 : RUN npm install --save cors apollo-server-express express graphql reflect-metadata type-graphql apollo-datasource-rest soap jsonwebtoken --yes
---> Running in 1e4472bcd901
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: apollo-express-server#1.0.0
npm ERR! Found: graphql#15.4.0
npm ERR! node_modules/graphql
npm ERR! graphql#"^15.3.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer graphql#"^0.12.0 || ^0.13.0 || ^14.0.0" from graphql-middleware#4.0.2
npm ERR! node_modules/graphql-middleware
npm ERR! graphql-middleware#"^4.0.2" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /root/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-11-05T16_19_42_605Z-debug.log
ERROR: Service 'apollo' failed to build : The command '/bin/sh -c npm install --save cors apollo-server-express express graphql reflect-metadata type-graphql apollo-datasource-rest soap jsonwebtoken --yes' returned a non-zero code: 1
There is not need to downgrade to npm 6.
Indeed npm 7 can still be used with option --legacy-peer-deps.
npm install --legacy-peer-deps
The problem here is certainly with NPM and the packages you are trying to install rather than anything to do with Docker.
Unfortunately, I am not able to reproduce the exact error that you are facing. That could be because:
something changed in the time between now and whenever this problem occurred;
there are some essential details that you are not showing us.
Either way, there's a general way in which such issues are solved, which should help. But first an explanation.
Dependencies, peer dependencies and conflicts
NPM's package (dependency) management mechanism allows packages (dependencies) to have:
(direct) dependencies - installed automatically with the package;
peer dependencies - have to be manually installed by the consumer of the package.
However, NPM does not allow multiple versions of the same package to coexist.
Also, as you may know, packages use standard semantic versioning, which means that a major version change indicates a breaking change.
Due to these two reasons, clashes occur if one package requires dependency A to be v1, while another wants the same dependency A to be v2.
NPM v7
NPM v7 was recently released and this is the version that current (as of November 2020) node:current images use.
Probably the biggest changes brought about by NPM7 relate to peer dependencies - NPM should now be able to install them automatically, if possible. Read more here.
As described in the document, in cases where it's not possible to solve the conflicts, NPM should now throw errors rather than warnings, which is what you are seeing.
I, on the other hand, only managed to get warnings and no errors using your setup and NPM v7.0.8, and I don't know why. The problems reported were essentially the same, however, so the resolution ought to be very similar.
How to solve conflicts
The only solution that I'm aware of is manual conflict resolution - the developer needs to adjust their dependencies to play along.
In your specific case the problem seems to be with the graphql package. The latest graphql package is v15, which is also a peer dependency of the latest type-graphql package (v1).
However, apollo-server-express has a few dependencies, which apparently only support graphql up to and including v14.
While you wait for apollo-server-express to fully support v15, you may opt for graphql v14 altogether by downgrading the only package that requires v15. So if you change your npm install to this:
npm install --save cors apollo-server-express express graphql#14 reflect-metadata type-graphql#0 apollo-datasource-rest soap jsonwebtoken
it ought to work... Notice that we are explicitly installing graphql#14 and type-graphql#0 (yes, version zero).
Alternative solution
Going to give you some bad advice too. In some cases a missing peer dependency may not be a problem, particularly if you never use the related functionality. In your case, it may be even less of a problem because you do have the dependency, just not the required version. It's entirely possible that a wrong version would do just fine. If you feel lucky (or if you're sure of you're doing) and you really wish to proceed with graphql v15, you could either:
suppress any NPM output to silence the errors;
downgrade to NPM v6, which works quite differently (although it will still warn you of peer dependency problems).
Proceed with caution!
I have a similar error, in my case just need to manually install all dependencies
npm install --save express
npm install --save express-graphql
npm install --save graphql
npm install --save mongoose
npm install package_name --legacy-peer-deps
Or
npm install package_name --force
Will fix the issue.
I had the same issue while trying to build a reactJS application in which i had used CoreUI and other JS libraries. Some of this dependacies i noted they use legacy dependacies in them and seemed like in their package.json file they have explicitly specified a version to be used. After trying all this solutions above, docker (docker build .) still could not build my image.
i changed my base image from node:16-alpine3.11 to node:12-alpine3.11 and everything worked perfectly.
Using this base image i was able to avoid using
npm install --save --legacy-peer-deps which failed to work on my case
My recommendations to anyone who might experience this issues is to just try various node docker images.
Related
This is confusing so I apologize if I don't word this sufficiently well.
Essentially, I'm leveraging npm's --force flag to bypass a conflicting peer-dependency error with npm#8. Subsequent npm install s of the dependencies complete without any errors. When attempting to install dependencies via docker, however, the original error returns.
So, originally:
encounter error:
npm ERR! ERESOLVE could not resolve
...
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
bypass via npm install --force
subsequent npm installs work without issue in new local environments (e.g. clone into new dir, run npm install)
However, attempting to npm install or npm ci (npm ci ensures a lockfile already exists) in a docker build continues throws the original error:
npm ERR! ERESOLVE could not resolve
...
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
Which, to me, suggests the lockfile isn't being respected. But we know it exists because otherwise npm ci would error.
Does anyone have an idea as to why this might be the case?
Dockerfile I'm testing with:
# // Dockerfile
# ==== CONFIGURE =====
# Use a Node 16 base image
FROM node:16-alpine
# Set the working directory to /app inside the container
WORKDIR /app
# Copy app files
COPY package-lock.json .
RUN echo $(ls)
# ==== BUILD =====
# Install dependencies (npm ci makes sure the exact versions in the lockfile gets installed)
RUN npm ci
# Build the app
RUN npm run build
# ==== RUN =======
# Set the env to "production"
ENV NODE_ENV production
# Expose the port on which the app will be running (3000 is the default that `serve` uses)
EXPOSE 3000
# Start the app
CMD [ "npx", "serve", "build" ]
Local npm is v8.1, docker npm is v8.19. Seems they introduced a breaking change at some point between those two versions.
From official docs:
NOTE: If you create your package-lock.json file by running npm install with flags that can affect the shape of your dependency tree, such as --legacy-peer-deps or --install-links, you must provide the same flags to npm ci or you are likely to encounter errors. An easy way to do this is to run, for example, npm config set legacy-peer-deps=true --location=project and commit the .npmrc file to your repo.
I'm trying to install randomstring package into Cypress container because my tests are using it.
Dockerfile:
FROM cypress/base:17.8.0
RUN npm install randomstring#1.2.2
RUN npm install cypress#7.0.0
COPY . /e2e
RUN npm cypress run
error output I'm getting:
1 error occurred:
* Status: The command '/bin/sh -c npm install randomstring#1.2.2 cypress#7.0.0' returned a non-zero code: 1, Code: 1
I'm aware that Cypress/base image comes with operating system and dependencies required in order to run Cypress but I'm not sure if npm is included.
What is the right way to install packages into Cypress container ?
Any particular reason to use base image?
Have you tried with cypress/included:7.0.0, which already has cypress + browsers installed.
Furthermore it's better to keep all your dependencies (randomstring included) in package.json file where they belong, copy it over and call npm install or npm ci.
I'm trying to build a vue/quasar app with the Dockerfile and face some errors:
The command '/bin/sh -c quasar build' returned a non-zero code: 1
I am using the latest LTS node version.
running the command: npx quaser build in the app directory does all the job properly, but doesn't work with the Dockerfile.
this is my Dockerfile:
FROM node:latest as build-stage
COPY package*.json ./
RUN npm install
RUN npm -g install #quasar/cli
RUN npm -g install #vue/cli
COPY ./ .
RUN quasar build
FROM nginx as production-stage
RUN mkdir /app
COPY --from=build-stage /dist/spa /app
COPY nginx.conf /etc/nginx/nginx.conf
this is all the output:
(base) ysgtr#tex-len:~/tex/test$ docker build -t quaser .
Sending build context to Docker daemon 4.085MB
Step 1/11 : FROM node:latest as build-stage
latest: Pulling from library/node
647acf3d48c2: Pull complete
b02967ef0034: Pull complete
e1ad2231829e: Pull complete
5576ce26bf1d: Pull complete
a66b7f31b095: Pull complete
2f540184b4cf: Pull complete
42cd32d0102f: Pull complete
b8b4c8e22bcd: Pull complete
48e4c368fbe9: Pull complete
Digest: sha256:22f1866405ad50bb1d141739596ba803aed073d618ab2ae6d5e66aedcf9261b5
Status: Downloaded newer image for node:latest
---> 6dc0a5fbad51
Step 2/11 : COPY package*.json ./
---> f80875173de5
Step 3/11 : RUN npm install
---> Running in 1282a9fbc81b
npm WARN deprecated uuid#3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated querystring#0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated coffee-script#1.12.7: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
added 1183 packages, and audited 1184 packages in 23s
133 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
npm notice
npm notice New patch version of npm available! 8.1.2 -> 8.1.4
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v8.1.4>
npm notice Run `npm install -g npm#8.1.4` to update!
npm notice
Removing intermediate container 1282a9fbc81b
---> e13c67d85f7b
Step 4/11 : RUN npm -g install #quasar/cli
---> Running in 9d0f4ba8e061
npm WARN deprecated coffee-script#1.12.7: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
added 373 packages, and audited 374 packages in 13s
35 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
Removing intermediate container 9d0f4ba8e061
---> 2669c81c7f92
Step 5/11 : RUN npm -g install #vue/cli
---> Running in 8340d87251db
npm WARN deprecated uuid#3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated uuid#3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated urix#0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated resolve-url#0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated har-validator#5.1.5: this library is no longer supported
npm WARN deprecated graphql-extensions#0.15.0: The `graphql-extensions` API has been removed from Apollo Server 3. Use the plugin API instead: https://www.apollographql.com/docs/apollo-server/integrations/plugins/
npm WARN deprecated apollo-tracing#0.15.0: The `apollo-tracing` package is no longer part of Apollo Server 3. See https://www.apollographql.com/docs/apollo-server/migration/#tracing for details
npm WARN deprecated apollo-cache-control#0.14.0: The functionality provided by the `apollo-cache-control` package is built in to `apollo-server-core` starting with Apollo Server 3. See https://www.apollographql.com/docs/apollo-server/migration/#cachecontrol for details.
npm WARN deprecated #hapi/bourne#1.3.2: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated #hapi/address#2.1.4: Moved to 'npm install #sideway/address'
npm WARN deprecated #hapi/hoek#8.5.1: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated request#2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated #hapi/topo#3.1.6: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated #hapi/joi#15.1.1: Switch to 'npm install joi'
npm WARN deprecated graphql-tools#4.0.8: This package has been deprecated and now it only exports makeExecutableSchema.\nAnd it will no longer receive updates.\nWe recommend you to migrate to scoped packages such as #graphql-tools/schema, #graphql-tools/utils and etc.\nCheck out https://www.graphql-tools.com to learn what package you should use instead
added 947 packages, and audited 948 packages in 37s
65 packages are looking for funding
run `npm fund` for details
15 vulnerabilities (8 moderate, 7 high)
To address issues that do not require attention, run:
npm audit fix
Some issues need review, and may require choosing
a different dependency.
Run `npm audit` for details.
Removing intermediate container 8340d87251db
---> 3ecd65ef8620
Step 6/11 : COPY ./ .
---> 22470e123db7
Step 7/11 : RUN quasar build
---> Running in 0ab8824d1c93
___
/ _ \ _ _ __ _ ___ __ _ _ __
| | | | | | |/ _` / __|/ _` | '__|
| |_| | |_| | (_| \__ \ (_| | |
\__\_\\__,_|\__,_|___/\__,_|_|
Running #quasar/cli v1.2.2
Example usage
$ quasar <command> <options>
Help for a command
$ quasar <command> --help
$ quasar <command> -h
Options
--version, -v Print Quasar CLI version
Commands
create Create a project folder
info Display info about your machine
(and your App if in a project folder)
upgrade Check (and optionally) upgrade Quasar packages
from a Quasar project folder
serve Create an ad-hoc server on App's distributables
help, -h Displays this message
--------------
=> IMPORTANT !
=> Trigger this inside of a Quasar project (and npm/yarn install) for more commands.
--------------
Error Unknown command "build"
The command '/bin/sh -c quasar build' returned a non-zero code: 1
things I tried:
changing the order of commands (quasar/cli before vue and the oposite).
deleting the dist/ and node_modules/ folder before running the docker file.
replaced quaser build in the dockerfile with RUN npx quasar build
So I found a way to resolve the problem, basically, I stated the WORKDIR and copied the quasar.conf.js file. Hope this helps others.
FROM node:latest as build-stage
WORKDIR /app
COPY package*.json ./
COPY quasar.conf.js ./
COPY ./ ./
RUN npm install
RUN npm install -g #vue/cli
RUN npm install -g #quasar/cli
RUN quasar build
FROM nginx as production-stage
RUN mkdir /app
COPY --from=buildenv /app/dist/spa /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
All docker images I try to create gets corrupted at the point of running npm install.
Two of those images gave errors like this :
[stage-1 4/5] RUN npm install -g pm2 --loglevel warn
→ npm ERR! Unexpected end of JSON input while parsing near '..."2.3.7","dependencies'
And then this
[src 4/20] RUN npm install lerna --global
→ npm ERR! Unexpected end of JSON input while parsing near '.../changed","version":"'
While the others just get stuck while installing anything related to lerna.
My colleagues don't have this issues, so it does not make any sense to change anything in the build steps.
I am quite confused about this.
Note: I have ran docker system prune -a to remove all caches so I can start afresh but the issues lingers all the same.
Could you try setting registry?
npm config set registry https://registry.npmjs.org/
I am trying to create a docker image that I can pack an aspnetcore2.0/angular-universal application and due to my insufficient docker experience I been keep running into issues. I could really use some help.
Here is the dockerfile content:
FROM microsoft/aspnetcore-build:2.0 AS build-env
WORKDIR /app
COPY *.csproj ./
RUN npm cache clean --force
RUN npm install npm#latest
RUN npm install #angular/cli#latest
RUN npm install #ngtools/webpack#next
RUN node -v
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o out
FROM microsoft/microsoft/aspnetcore:2.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT [ "dotnet", "net-streetStyleCrew.dll" ]
since the aspnetcore-build:2.0 comes with a too old npm/node it has to be updated. And it have not go to angular-cli part, but i assume that need to be fresh as well of course.
And here is the trouble that I am running into now, and i have no clue how to resolve what appears to be a network issue inside the container when attempts to update:
Step 5/15 : RUN npm install npm#latest
---> Running in 72531196fc83
npm ERR! Windows_NT 10.0.16299
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "npm#latest"
npm ERR! node v6.13.0
npm ERR! npm v3.10.10
npm ERR! code ENOTFOUND
npm ERR! errno ENOTFOUND
npm ERR! syscall getaddrinfo
npm ERR! network getaddrinfo ENOTFOUND registry.npmjs.org registry.npmjs.org:443
npm ERR! network This is most likely not a problem with npm itself
npm ERR! network and is related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
npm ERR! Please include the following file with any support request:
npm ERR! C:\app\npm-debug.log
The command 'cmd /S /C npm install npm#latest' returned a non-zero code: 1
I am trying to run this on a windows container, because I don't have a whole lot of experience with Linux either.
I am absolutely open to any suggestion as well that could improve my approach to the basic concept. Thanks in advance.
Firstly, I think the specific issue is not a Docker related issue. This is a network related issue. Maybe this SO thread will help.
Regarding your Dockerfile:
The official best practice recommends reducing the number of layers. Each RUN command creates a layer. At the same time, you may want to have multiple RUN command to improve readability and take the benefit of caching. So, you need to find a balance between the two. In this particular case, I think you should chain the npm commands in a single RUN statement.
Also, I think instead of using the latest version, you should specify the exact version. The latest will always download the latest at the time of image creation and you don't know whether this new version is having a bug that breaks your app. So, the idea is to test in a specific version and use that same version in production. If you want to upgrade later to more recent version, you need to first test your app with the new version and then update your Dockerfile with the new version
Here is an e.g.
RUN mkdir /home/aus/.npm; \
npm config set prefix /home/aus/.npm; \
npm install --quiet --no-progress -g webpack#3.11.0; \
npm install --quiet --no-progress -g #angular/cli#1.7.2; \
npm install --quiet --no-progress;