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

pants run for nodejs only works if package.json in root directory #21793

Open
kdowney-talos opened this issue Dec 22, 2024 · 0 comments
Open
Labels

Comments

@kdowney-talos
Copy link

kdowney-talos commented Dec 22, 2024

Describe the bug
The pants run goal fails with:

(.venv) serenitydev@c774de47c447:~/bug_report$ pants run //serenity.middleware:js#generate-asyncapi
15:11:54.20 [INFO] Completed: Installing [email protected].
yarn run v1.22.10
error Couldn't find a package.json file in "/tmp/pants-sandbox-YWbbQa"
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

if and only if the package.json is in a sub-directory in the monorepo; if at root next to pants.toml, it works.

See details below for fully reproducible test case.

Pants version
2.25.0.dev2 (also observed in 2.23.x)

OS
Ubuntu 22.04 as dev container hosted inside VS Code on MacOS 15.2 (ARM64)

Linux c774de47c447 6.10.14-linuxkit #1 SMP Fri Nov 29 17:22:03 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux

Additional info

pants.toml

[GLOBAL]
pants_version = "2.25.0.dev2"
backend_packages = [
  "pants.backend.experimental.javascript",
]

[nodejs]
version = "v22"

BUILD

package_json(
    name="js",
    source="package.json",
    scripts=[
        node_build_script(entry_point="generate-asyncapi"),
    ],
)

package.json

{
    "name": "asyncapi-generator",
    "version": "0.0.1",
    "description": "Stub to install AsyncAPI Generator",
    "private": true,
    "type": "module",
    "scripts": {
        "generate-asyncapi": "asyncapi generate model"
    },
    "dependencies": {
        "@asyncapi/generator": "^1.0.0"
    },
    "packageManager": "[email protected]"
}

If you put these three files in the same directory and run:

pants run //:js#generate-asyncapi

You'll get an error like this (expected -- bad run command):

(.venv) serenitydev@c774de47c447:~/bug_report$ pants run //:js#generate-asyncapi
yarn run v1.22.10
$ asyncapi generate model
/bin/sh: 1: asyncapi: not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

but if you simply move BUILD and package.json into a sub-directory, it fails with the reported error:

(.venv) serenitydev@c774de47c447:~/bug_report$ mkdir serenity.middleware
(.venv) serenitydev@c774de47c447:~/bug_report$ mv BUILD package.json serenity.middleware/
(.venv) serenitydev@c774de47c447:~/bug_report$ pants run //serenity.middleware:js#generate-asyncapi
yarn run v1.22.10
error Couldn't find a package.json file in "/tmp/pants-sandbox-AcIIZR"
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

My expectation is that each sub-directory in a monorepo will be treated as a standalone module, and that package.json does not have to be globally available at root. For our project I can work around this -- we only have have module which requires NodeJS, and it's for installing a CLI code generation tool --but it seems out of step with the rest of Pants.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant