<#21793 pants run for nodejs only works if package...
# github-notifications
c
#21793 pants run for nodejs only works if package.json in root directory Issue created by kdowney-talos Describe the bug The
pants run
goal fails with:
Copy code
(.venv) serenitydev@c774de47c447:~/bug_report$ pants run //serenity.middleware:js#generate-asyncapi
15:11:54.20 [INFO] Completed: Installing asyncapi-generator@0.0.1.
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)
Copy code
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": "yarn@1.22.10" } If you put these three files in the same directory and run:
Copy code
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. pantsbuild/pants