Hey everyone, evaluating Pants for our monorepo he...
# general
l
Hey everyone, evaluating Pants for our monorepo here. Currently trying to use
adhoc_tool
to install our node dependencies using
pnpm
while javascript support is not yet ready. I’m having some issues with post-install scripts in
core-js
and
cpu-features
. Has anyone faced anything like that and have any tips for me?
w
What’s the problem you’re running into specifically, and what does your build file look like?
l
First issue I think is with node-gyp. I’d need to add node-gyp as a dependency but since it’s a symlink,
system_binary
says it can’t find it in my path.
Second issue is just
core-js
failing without any reason really. 😐
Here’s my config:
Copy code
files(
    name = "package-config",
    dependencies = [],
    sources = [
        "package.json",
        "pnpm-workspace.yaml",
        "pnpm-lock.yaml",
        ".npmrc",
    ],
)

# Require node 18
system_binary(
    name = "node",
    binary_name = "node",
    extra_search_paths = [env("HOME") + "/.nvm/versions/node/v18.12.0/bin"],
    fingerprint = r"v18.12.0",
    fingerprint_args = ["--version"],
)

# system_binary(
#     name = "node-gyp",
#     binary_name = "node-gyp.js",
#     extra_search_paths = [env("HOME") + "/.nvm/versions/node/v18.12.0/lib/node_modules/node-gyp/bin"],
# )

# Require pnpm v8
system_binary(
    name = "pnpm",
    binary_name = "pnpm",
    extra_search_paths = [env("HOME") + "/.nvm/versions/node/v18.12.0/bin"],
    fingerprint = r"8\..*\..*",
    fingerprint_args = ["--version"],
    fingerprint_dependencies = [":node"],
)

# Fetch the dependencies and produce a `node_modules` directory
adhoc_tool(
    name = "node-modules",
    timeout = 300,
    args = ["install"],
    execution_dependencies = [":package-config"],
    output_dependencies = [":package-config"],
    output_directories = ["node_modules"],
    runnable = ":pnpm",
    runnable_dependencies = [
        ":node",
        ":node-gyp",
    ],
)
Just following up the only way I could solve this was setting ignore-scripts=true and moving on. Guess it will do for now 😐
b
What was the error output?
l
Copy code
.../core-js@2.6.12/node_modules/core-js postinstall$ node -e "try{require('./postinstall')}catch(e){}"
undefined
 ELIFECYCLE  Command failed with exit code -2.

stderr:
No more info than this unfortunately. I think pnpm has issues showing the errors when a process it spawns fails
I was having the same problem when doing a
pnpm build
instead of a
pnpm next build
. Instead of showing me the output coming from next (which was that it can’t find
sed
,
uname
and
dirname
in the sandbox) it just showed me an exit code -2
b
Ah, hm, how annoying that pnpn isn’t being specific. I think we had to have
sh
in the sandbox for some of our npm installs, that might include core-js… so maybe yet another system binary would help 🤷‍♂️ More generally, are you aware of the —`keep-sandboxes=on_failure` arg to pants? It gives you the sandbox and command (in __run.sh) that pants executed to introspect/debug… although if you’re unblocked, that might not be needed for now
l
HA!
sh
was indeed the culprit!
👍 1
Now I’m back at sed, uname and dirname… lol. But for the install target. I wonder if there’s a better way to provide the environment to the sandbox than this.
More generally, are you aware of the —`keep-sandboxes=on_failure` arg to pants? It gives you the sandbox and command (in __run.sh) that pants executed to introspect/debug… although if you’re unblocked, that might not be needed for now
Yeah, I’m aware! It’s been a lifesaver when it comes to these mysterious pnpm errors
👍 1
b
Yeah, “huge list of `system_binary`” isn’t very nice, especially with a such opaque method to determine which are required :(
👍 1
l
Maybe a list of commonly used binaries used for building all added as one target to the sandbox? Like apt’s
build-essential
but with a few common bash tools like
dirname
,
sed
and
uname
.