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.26k stars 871 forks source link

Cannot find 'grunt' while Running grunt task #524

Open johnnybigoode-zz opened 7 years ago

johnnybigoode-zz commented 7 years ago

I'm sorry for making yet another topic on the subject, but the current solutions aren't working for me.

I got the whole thing working, then I installed a 'grunt-front-end-loader', which seems like a bad idea in retrospect (https://www.npmjs.com/package/grunt-front-end-modules)

This is my mvn clean install output:

$ mvn clean install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building npm-maven-base-project 0.0.1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ npm-maven-base-project ---
[INFO]
[INFO] --- frontend-maven-plugin:1.3:install-node-and-npm (Install node and npm) @ npm-maven-base-project ---
[INFO] Found proxies: [1{protocol='http', host='localhost', port=40080, with username/passport authentication}, 2{protocol='https', host='localhost', port=40080, with username/passport authentication}]
[INFO] Node v4.6.0 is already installed.
[INFO] NPM 2.15.9 is already installed.
[INFO]
[INFO] --- frontend-maven-plugin:1.3:grunt (grunt build) @ npm-maven-base-project ---
[INFO] Running 'grunt ' in C:\projetos\tutorials\npm-maven\maven-arch
[ERROR] module.js:327
[ERROR]     throw err;
[ERROR]     ^
[ERROR]
[ERROR] Error: Cannot find module 'C:\projetos\tutorials\npm-maven\maven-arch\node_modules\grunt-cli\bin\grunt'
[ERROR]     at Function.Module._resolveFilename (module.js:325:15)
[ERROR]     at Function.Module._load (module.js:276:25)
[ERROR]     at Function.Module.runMain (module.js:441:10)
[ERROR]     at startup (node.js:139:18)
[ERROR]     at node.js:974:3
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

The frontend-maven-plugin part:

<plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <version>1.3</version>
                <configuration>
                    <nodeVersion>v4.6.0</nodeVersion>
                    <npmVersion>2.15.9</npmVersion>
                </configuration>
                <executions>
                    <execution>
                        <id>Install node and npm</id>
                        <goals>
                            <goal>install-node-and-npm</goal>
                        </goals>
                        <phase>generate-sources</phase>
                    </execution>
                    <execution>
                        <id>npm Install</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>install grunt</arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>grunt build</id>
                        <goals>
                            <goal>grunt</goal>
                        </goals>
                        <phase>generate-sources</phase>
                    </execution>
                </executions>

            </plugin>

And the package.json part

{
  "name": "npm-maven-base-project",
  "version": "0.0.1",
  "devDependencies": {
    "grunt": "~0.4.5",
    "grunt-cli": "1.2.0",
    "grunt-babel": "^6.0.0",
    "grunt-contrib-jshint": "~0.10.0",
    "grunt-contrib-nodeunit": "~0.4.1",
    "grunt-contrib-uglify": "~0.5.0",
    "load-grunt-tasks": "^3.5.2"
  },
  "main": "GruntFile.js",
  "dependencies": {
    "babel-preset-es2015": "^6.18.0",
    "babel": "^6.5.2",
    "grunt-cli": "1.2.0",
    "grunt-contrib": "^0.11.0",
    "grunt-contrib-coffee": "^0.10.1",
    "grunt-contrib-clean": "^0.5.0",
    "grunt-contrib-compass": "^0.7.2",
    "grunt-contrib-concat": "^0.4.0",
    "grunt-contrib-connect": "^0.7.1",
    "grunt-contrib-compress": "^0.8.0",
    "grunt-contrib-copy": "^0.5.0",
    "grunt-contrib-csslint": "^0.2.0",
    "grunt-contrib-cssmin": "^0.9.0",
    "grunt-contrib-imagemin": "^0.7.2",
    "grunt-contrib-htmlmin": "^0.2.0",
    "grunt-contrib-handlebars": "^0.8.0",
    "grunt-contrib-jade": "^0.11.0",
    "grunt-contrib-jasmine": "^0.6.5",
    "grunt-contrib-jshint": "^0.10.0",
    "grunt-contrib-jst": "^0.6.0",
    "grunt-contrib-less": "^0.11.4",
    "grunt-contrib-qunit": "^0.4.0",
    "grunt-contrib-nodeunit": "^0.3.3",
    "grunt-contrib-requirejs": "^0.4.4",
    "grunt-contrib-sass": "^0.7.4",
    "grunt-contrib-stylus": "^0.15.1",
    "grunt-contrib-symlink": "^0.3.0",
    "grunt-contrib-uglify": "^0.4.1",
    "grunt-contrib-watch": "^0.6.1",
    "grunt-contrib-yuidoc": "^0.5.2",
    "load-grunt-tasks": "^3.5.2"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

Just a FYI, I was using this to guide me in transcoding some JS. http://mabboud.net/how-to-uglify-and-transpile-ecma6-javascript-with-a-maven-war-build/

csaban commented 7 years ago

Probably late now, but:

You need grunt-cli installed as your project dependency. It is already listed in your package.json.

In the pom.xml - instead of installing grunt only under npm, use install - to install all package.json dependencies.

The linked article also uses npm install.

Change the npm install execution section to look like this:

                                       <execution>
                        <id>npm Install</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>install</arguments>
                        </configuration>
                    </execution>