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

Unable to run npx commands #1149

Open
vincentol opened this issue Jun 5, 2024 · 8 comments
Open

Unable to run npx commands #1149

vincentol opened this issue Jun 5, 2024 · 8 comments

Comments

@vincentol
Copy link

vincentol commented Jun 5, 2024

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)

@eirslett
Copy link
Owner

eirslett commented Jun 6, 2024

Is there a reason you absolutely need npx? The "normal" approach is to add scripts to package.json and run those from Maven?

@vincentol
Copy link
Author

vincentol commented Jun 10, 2024

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

@LMatass
Copy link

LMatass commented Jun 20, 2024

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.

@Viciouss
Copy link

Viciouss commented Jul 2, 2024

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.

@eirslett
Copy link
Owner

eirslett commented Jul 2, 2024

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"
}

@Viciouss
Copy link

Viciouss commented Jul 2, 2024

@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.

@eirslett
Copy link
Owner

eirslett commented Jul 4, 2024

What did the script entry look like? There's no sonar-scanner in the current example...

@thomrick
Copy link

thomrick commented Jul 4, 2024

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.

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

No branches or pull requests

5 participants