Unable to run `npx` commands
vincentol opened this issue · 8 comments
Do you want to request a feature or report a bug?
Bug
I can't run npx
commands unless I explicitly add a step to install npx
globally.
🙏 Hoping I'm just misconfiguring something somewhere because the docs and other issues seem to have this working.
The end goal is to have this npx
command running in a preinstall
script, which should have been fixed in: #1002
What is the current behavior?
Any npx
command I try is failing
[INFO] Running 'npx cowsay hello' in /Users/volim/dev/project/react
[INFO] npm ERR! code ENOENT
[INFO] npm ERR! syscall lstat
[INFO] npm ERR! path /Users/volim/dev/project/target/lib
[INFO] npm ERR! errno -2
[INFO] npm ERR! enoent ENOENT: no such file or directory, lstat '/Users/volim/dev/project/target/lib'
[INFO] npm ERR! enoent This is related to npm not being able to find a file.
[INFO] npm ERR! enoent
[INFO]
If the current behavior is a bug, please provide the steps to reproduce.
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.15.0</version>
<configuration>
<workingDirectory>react</workingDirectory>
<installDirectory>${project.build.directory}</installDirectory>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<phase>generate-resources</phase>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v21.7.3</nodeVersion>
<npmVersion>10.2.4</npmVersion>
</configuration>
</execution>
<execution>
<id>say hello</id>
<goals>
<goal>npx</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>cowsay hello</arguments>
</configuration>
</execution>
<plugin>
What is the expected behavior?
Should be able to run npx
commands -> as mentioned in the readme
Please mention your frontend-maven-plugin and operating system version.
frontend-maven-plugin: 1.15.0
OS: MacOS 14.1.2 (Sonoma)
Is there a reason you absolutely need npx? The "normal" approach is to add scripts to package.json
and run those from Maven?
We have a private package uploaded to our google artifact registry, we run a command with npx
to authenticate into it:
https://cloud.google.com/artifact-registry/docs/nodejs/authentication#get-token
We actually do have a script in our package.json, but it just calls that npx command (we got it from the artifact registry docs). When I did some digging, I discovered that it was failing because we couldn't run any npx
commands from Maven
Similar issue here, I want to build my app and then apply some rollup configuration so I use the following package.json script:
"build:single": "ng build --output-hashing=none --named-chunks=true && npx rollup -c rollup.config.mjs",
Which is failing with:
[INFO] sh: 1: npx: not found
[INFO]  ELIFECYCLE  Command failed.
I'm facing the same issue while running sonarqube-scanner with npx. I upgraded a project from npm 8.5.x to a recent 10.x version which broke the scanner execution with the ENOENT error. There is a folder called 'node' in target/frontend-binaries which contains npm and npx binaries, but there is no 'lib' folder next to it.
I went looking for the exact npm version for which it breaks, which turns out to be 8.16.0. Anything lower than that is working just fine for me. I'm using Linux, Java 17, Maven 3.9.6.
You shouldn't really need npx
as long as the command is defined inside package.json
. Just remove it. Try this:
"scripts": {
"build:single": "ng build --output-hashing=none --named-chunks=true && rollup -c rollup.config.mjs"
}
@eirslett I tried adding a script entry for it, but it doesn't find the sonar-scanner this way, command not found. I also tried installing it globally before calling it which did not help either. Next I tried a shell script, same issue.
What did the script entry look like? There's no sonar-scanner in the current example...
Hi! Same issue here.
Regarding the logs we see the copy of node binary but not the embedded toolchain.
Why npx
? Because it can act like a script but using packages not requiring specific configuration without extra dependency management.
In our case we would like to use npx
for checking optimized dependencies information in the yarn.lock file after dependency upgrades. The idea is to run the next command before the yarn install
goal:
npx yarn-deduplicate yarn.lock --list --fail
This will prevent installation of unwanted duplicated modules that may issue unexpected behavior during build, test, lint goals.
In other hand it would be great to be able to use the full node toolchain for such use cases.