Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug?]: Missing package: typescript@patch:typescript@npm #6501

Open
1 task
uchar opened this issue Sep 13, 2024 · 1 comment
Open
1 task

[Bug?]: Missing package: typescript@patch:typescript@npm #6501

uchar opened this issue Sep 13, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@uchar
Copy link

uchar commented Sep 13, 2024

Self-service

  • I'd be willing to implement a fix

Describe the bug

a very simple packge.json with

...
  "scripts": {
    "build": "tsc"
  },
 "dependencies": {
    "@types/node": "22.5.2",
    "tslib": "2.7.0",
    "typescript": "5.5.4"
  },
"packageManager": "[email protected]"
....

and a dockerfile

FROM node:20-alpine AS dependencies
RUN corepack enable
WORKDIR /app
COPY package.json ./
COPY yarn.lock ./
RUN yarn --immutable

FROM node:20-alpine AS builder
RUN corepack enable
WORKDIR /app
COPY --from=dependencies /app/package.json ./
COPY --from=dependencies /app/.pnp.cjs ./
COPY --from=dependencies /app/.yarn ./.yarn
COPY --from=dependencies /app/yarn.lock ./
COPY ./src ./src
RUN yarn build


FROM node:20-alpine AS runner
RUN corepack enable
WORKDIR /app
COPY --from=builder /app/build ./
COPY --from=dependencies /app/.pnp.cjs ./
COPY --from=dependencies /app/.yarn ./.yarn
ENTRYPOINT ["node", "src/testCode.js"]

fails with error

 > [builder 9/9] RUN yarn build:
1.157 ! Corepack is about to download https://repo.yarnpkg.com/4.4.1/packages/yarnpkg-cli/bin/yarn.js
3.298 /app/.pnp.cjs:5676
3.298     throw firstError;
3.298     ^
3.298
3.298 Error: Required package missing from disk. If you keep your packages inside your repository then restarting the Node process may be enough. Otherwise, try to run an install first.
3.298
3.298 Missing package: typescript@patch:typescript@npm%3A5.5.4#optional!builtin<compat/typescript>::version=5.5.4&hash=379a07
3.298 Expected package location: /root/.yarn/berry/cache/typescript-patch-fe43cd9db9-10c0.zip/node_modules/typescript/
3.298
3.298     at require$$0.Module._resolveFilename (/app/.pnp.cjs:5675:13)
3.298     at Module._load (node:internal/modules/cjs/loader:1051:27)
3.298     at require$$0.Module._load (/app/.pnp.cjs:5566:31)
3.298     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
3.298     at node:internal/main/run_main_module:28:49

yarn build outside docker works fine !

To reproduce

Clone https://github.com/uchar/yarnbugs/tree/multistage_typescript_patch_error move to branch multistage_typescript_patch_error
Then run

yarn
docker build -t yarn_bug .

you will see the error

4.967 Error: Required package missing from disk. If you keep your packages inside your repository then restarting the Node process may be enough. Otherwise, try to run an install first.
4.967
4.967 Missing package: typescript@patch:typescript

Environment

System:
    OS: Linux 5.15 Alpine Linux
    CPU: (16) x64 AMD Ryzen 7 5800H with Radeon Graphics
    Binaries:
    Node: 20.17.0 - /tmp/xfs-19d7b165/node
    Yarn: 4.4.1 - /tmp/xfs-19d7b165/yarn
    npm: 10.8.2 - /usr/local/bin/npm

Additional context

No response

@uchar uchar added the bug Something isn't working label Sep 13, 2024
@uchar
Copy link
Author

uchar commented Sep 13, 2024

It seems that with Yarn 4, we also need to copy the cache folder from dependencies(COPY --from=dependencies /root/.yarn /root/.yarn in this case).

The main issue here is the lack of proper documentation, there aren’t many guides available for the new yarn version, and most of the existing ones are outdated, simple upgrade take almost a complete day of trial/error for me

Perhaps a new entry in the documentation could be helpful ( e.g a guide on how to migrate yarn 1 dockerfiles to yarn 4 in https://yarnpkg.com/migration/guide )
e.g also for this one #6489 (comment) , I didnt find any document about not using YARN_COMMAND in your envs ( this wasnt a problem in yarn v1 )

I’ve already created a question on Stack Overflow and answered it myself, in case some one in future have this problem . https://stackoverflow.com/questions/78982144/upgrading-multistage-docker-from-yarn-1-to-yarn-modern

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant