eirslett / frontend-maven-plugin

"Maven-node-grunt-gulp-npm-node-plugin to end all maven-node-grunt-gulp-npm-plugins." A Maven plugin that downloads/installs Node and NPM locally, runs NPM install, Grunt, Gulp and/or Karma.
Apache License 2.0
4.21k stars 867 forks source link

npx should use project-local node_modules #1011

Open brandones opened 2 years ago

brandones commented 2 years ago

Do you want to request a feature or report a bug?

Report a bug.

What is the current behavior?

After running install-node-and-npm, running npx cowsay wow installs cowsay to the user global node_modules directory and runs it from there.

What is the expected behavior?

After running install-node-and-npm, running npx cowsay wow should install cowsay to node/node_modules in the project directory and run it from there.

Please mention your frontend-maven-plugin and operating system version.

frontend-maven-plugin: 1.11.3 OS: Ubuntu 21.10, Ubuntu 14.04

Code

        List<MojoExecutor.Element> configuration = new ArrayList<>();
        configuration.add(element("nodeVersion", "v16.2.0"));
        configuration.add(element("npmVersion", "7.13.0"));
        runFrontendMavenPlugin("install-node-and-npm", configuration);
        runFrontendMavenPlugin("npx", Collections.singletonList(element("arguments", "cowsay wow")));
eirslett commented 2 years ago

Oh, that could be a bit tricky... one "workaround" for now is to not use npx but instead use scripts in package.json and then do npm run-script... does that solve your specific problem?