yarnpkg / yarn

The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry
https://classic.yarnpkg.com
Other
41.37k stars 2.72k forks source link

Error: Couldn't find a package.json file #9011

Closed 666asd closed 7 months ago

666asd commented 7 months ago

npm ls -g yarn

npm WARN config global --global, --local are deprecated. Use --location=global instead. /opt/node/lib └── yarn@1.22.20

yarn --help

Error: Couldn't find a package.json file in "/" at MessageError.ExtendableBuiltin (/opt/node/lib/node_modules/yarn/lib/cli.js:721:66) at new MessageError (/opt/node/lib/node_modules/yarn/lib/cli.js:750:123) at /opt/node/lib/node_modules/yarn/lib/cli.js:41356:15 at Generator.next () at step (/opt/node/lib/node_modules/yarn/lib/cli.js:310:30) at /opt/node/lib/node_modules/yarn/lib/cli.js:321:13

jrsherry commented 7 months ago

Looks like this was introduced in the release this morning; 1.22.20

PhilippMeissner commented 7 months ago

Facing the same issues ever since 1.22.20. We fixed it by currently pinning our version to 1.22.19 via npm install -g yarn@1.22.19

HitLuca commented 7 months ago

for us what fixed it was removing a --cwd option

canderson-activatecare commented 7 months ago

Looks like this was introduced in the release this morning; 1.22.20

Confirming that this has also broken our pipeline due to --cwd flag no longer working. Also will be pinning to 1.22.19 for the time being.

Cyberboss commented 7 months ago

Here's a repro Dockerfile

FROM mcr.microsoft.com/dotnet/sdk:6.0-bookworm-slim AS build

# install node and npm
# replace shell with bash so we can source files
RUN curl --silent -o- https://raw.githubusercontent.com/creationix/nvm/v0.39.1/install.sh | sh

ENV NODE_VERSION 20.5.1

ENV NVM_DIR /root/.nvm
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH

RUN . $NVM_DIR/nvm.sh \
    && nvm install $NODE_VERSION \
    && nvm use $NODE_VERSION \
  && npx --yes yarn add svg-to-ico@1.0.14 svg2img@1.0.0-beta.2

Adding @1.22.19 to the yarn spec works fine

arcanis commented 7 months ago

I'm investigating. It seems the problem is triggered when calling Yarn through npx, as this fails:

cd $(mktemp -d) && yarn init -y && yarn install && mkdir foo && cd foo && npx yarn install

Whereas this works:

cd $(mktemp -d) && yarn init -y && yarn install && mkdir foo && cd foo && yarn install
martvalja commented 7 months ago

If this helps I'm facing the same issue, commands (Node version v18.16.0, npm version 9.5.1, macOS Sonoma 14.1.1)

        npm install -g yarn
        yarn set version 1

Result in

Error: Couldn't find a package.json file in "/Users/<username>/test"
    at /Users/<username>/test/.yarn/releases/yarn-1.22.20.cjs:43530:15
    at Generator.next (<anonymous>)
    at step (/Users/<username>/test/.yarn/releases/yarn-1.22.20.cjs:310:30)
    at /Users/<username>/test/.yarn/releases/yarn-1.22.20.cjs:321:13

This was fixed by pinning the yarn version to 1.22.19 as mentioned by @PhilippMeissner

arcanis commented 7 months ago

I have identified a fix; I'm working on releasing it

arcanis commented 7 months ago

I released the 1.22.21 which should have fixed this; can one of you confirm me that it looks good on your side?

jrsherry commented 7 months ago

I've confirmed this patch resolved my issue.

martvalja commented 7 months ago

Fixed for me as well, thank you for the prompt fix 👍