Closed Hexagon closed 8 months ago
@Hexagon I'm unable to reproduce the described issue. It works as expected on my end. I did this:
mkdir my-project
cd my-project
npm init -y # creates package.json
mkdir -p sub/sub1
cd sub/sub1
npx jsr add @cross/env # works as expected
Ah nvm I'm not able to reproduce it with npm
, but with pnpm
Oh, i'll try to narrow it down later, i used regular npm with latest node 21
I think I found the cause. The project directory detection code was flawed. Opened #57 to fix this.
The problem
When running
npx jsr add @cross/env
in a directory without a package.json file, and a package.json file exists in a parent directory, you do receive an error message like this:The same goes for
bunx jsr
Steps to reproduce
Create /home/user/package.json
Create a new folder /home/user/git/repo/ and cd to it
Run
npx jsr add @cross/env
Actual result
Above error message, saying that the package was not found
Expected result
Ideally, JSR should either:
Recognize that the current directory is a separate workspace, create package.json, and install the package.
Provide a more informative error message explaining that the identified workspace is not configured for jsr, and suggest solutions.
Workround
Create a valid package.json file in the directory where you want to install the package. This will override the parent directory's package.json and ensure that everything goes as planned.