nodejs / docker-node

Official Docker Image for Node.js :whale: :turtle: :rocket:
https://hub.docker.com/_/node/
MIT License
8.13k stars 1.95k forks source link

Using node LTS leads to error during docker run #2095

Open shuo-move opened 4 weeks ago

shuo-move commented 4 weeks ago

Version

v20.14.0

Platform

macOS

Subsystem

No response

What steps will reproduce the bug?

Dockerfile: FROM node:lts as base ... RUN yarn install --immutable --immutable-cache ... RUN yarn build ... CMD yarn start

repro steps:

  1. run command docker build -t test-image . and image should be built without error
  2. run command docker run -p 3000:3000 test-image and it leads to error
    
    error This project's package.json defines "packageManager": "yarn@3.5.0". However the current global version of Yarn is 1.22.22.

Presence of the "packageManager" field indicates that the project is meant to be used with Corepack, a tool included by default with all official Node.js distributions starting from 16.9 and 14.19. Corepack must currently be enabled by running corepack enable in your terminal. For more information, check out https://yarnpkg.com/corepack.


### How often does it reproduce? Is there a required condition?

It is 100% reproducible with node v20.14.0 (latest LTS). After pinned node version to 18.20.3, the issue is gone. 

I've tried lower version of node 20 like 20.9.0 and it has the same issue. 

FROM node:18.20.3 as base


### What is the expected behavior? Why is that the expected behavior?

The docker run command should not error out.

### What do you see instead?

 running command `docker run -p 3000:3000 test-image` leads to error:

error This project's package.json defines "packageManager": "yarn@3.5.0". However the current global version of Yarn is 1.22.22.

Presence of the "packageManager" field indicates that the project is meant to be used with Corepack, a tool included by default with all official Node.js distributions starting from 16.9 and 14.19. Corepack must currently be enabled by running corepack enable in your terminal. For more information, check out https://yarnpkg.com/corepack.



### Additional information

_No response_
marco-ippolito commented 4 weeks ago

"packageManager": "yarn@3.5.0" Looks like you are using a corepack feature without corepack being enabled. cc @nodejs/corepack

richardlau commented 3 weeks ago
error This project's package.json defines "packageManager": "yarn@3.5.0". However the current global version of Yarn is 1.22.22.

Presence of the "packageManager" field indicates that the project is meant to be used with Corepack, a tool included by default with all official Node.js distributions starting from 16.9 and 14.19.
Corepack must currently be enabled by running corepack enable in your terminal. For more information, check out https://yarnpkg.com/corepack.

This message is from yarn 1.22.20 and later:

A message will be displayed when Yarn 1.22 notices that the local project has a package.json file referencing a non-1.x Yarn release via the packageManager field. The message will explain that the project is intended to be used with Corepack.

It looks like the Docker images for Node.js 20 include yarn 1.22.22 while the image for Node.js 18 includes an older yarn 1.22.19 (i.e. before the behaviour was changed).

I'll move this issue to https://github.com/nodejs/docker-node.

LaurentGoderre commented 3 weeks ago

This error message is by design, it tells you that the package file is from a newer version of yarn. You would need to update yarn in your image.