1
votes

I generated my angular 2 project with angular-cli. I cannot upgrade to angular 4 because of project and customer constraints.

I try to use frontend-maven-plugin to compile my angular app with maven, but when I launch mvn clean install, the build script fails.

I got the error :

[ERROR] ..pathToProject/node_modules/@ngtools/json-schema/src/schema-class-factory.js:34 [ERROR] result.push(...indices); [ERROR]
^^^ [ERROR] [ERROR] SyntaxError: Unexpected token ... [ERROR] at exports.runInThisContext (vm.js:53:16) [ERROR] at Module._compile (module.js:373:25) [ERROR] at Object.Module._extensions..js (module.js:416:10) [ERROR] at Module.load (module.js:343:32) [ERROR] at Function.Module._load (module.js:300:12) [ERROR] at Module.require (module.js:353:17) [ERROR] at require (internal/module.js:12:17) [ERROR] at Object. (..pathToProject/node_modules/@ngtools/json-schema/src/index.js:3:30) [ERROR] at Module._compile (module.js:409:26) [ERROR] at Object.Module._extensions..js (module.js:416:10) [ERROR] [ERROR] npm ERR! Linux 4.4.0-92-generic [ERROR] npm ERR! argv "..pathToProject/node/node" "..pathToProject/node/node_modules/npm/bin/npm-cli.js" "run-script" "build" [ERROR] npm ERR! node v4.6.0 [ERROR] npm ERR! npm v2.15.9 [ERROR] npm ERR! code ELIFECYCLE [ERROR] npm ERR! [email protected] build: ng build [ERROR] npm ERR! Exit status 1 [ERROR] npm ERR! [ERROR] npm ERR! Failed at the [email protected] build script 'ng build'. [ERROR] npm ERR! This is most likely a problem with the hsmt package, [ERROR] npm ERR! not with npm itself. [ERROR] npm ERR! Tell the author that this fails on your system: [ERROR] npm ERR! ng build [ERROR] npm ERR! You can get information on how to open an issue for this project with: [ERROR] npm ERR! npm bugs hsmt

My pom :

<build>
     <plugins>
    <plugin>
     <groupId>com.github.eirslett</groupId>
     <artifactId>frontend-maven-plugin</artifactId>
     <version>1.5</version>
     <executions>
       <execution>
         <id>install node and npm</id>
         <goals>
           <goal>install-node-and-npm</goal>
         </goals>
         <configuration>
           <nodeVersion>v4.6.0</nodeVersion>
           <npmVersion>v2.15.9</npmVersion>
         </configuration>
       </execution>

       <execution>
         <id>build</id>
         <goals>
           <goal>npm</goal>
         </goals>
         <configuration>
           <arguments>run-script build</arguments>
         </configuration>
         <phase>generate-resources</phase>
       </execution>

     </executions>
       </plugin>
     </plugins>
</build>

My package.json :

{
  "name": "hsmt",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "ng": "ng",
    "start": "ng serve --proxy-config proxy.conf.json",
    "build": "ng build",
    "prod" : "ng build --prod",
    "test": "ng test",
    "pree2e": "webdriver-manager update --standalone false --gecko false",
    "e2e": "protractor",
    "prebuild": "npm install"
  },
2
<nodeVersion>v4.6.0</nodeVersion> :-o. current lts is 6.11.2. Check what version you are using outside of maven and stick to it in your pom.xml. BTW Is this error only appearing in maven ? (I assume yes) - n00dl3
Great this is working with node v6.11.2 :) (and this is indeed installed version on my computer) I've tried to upgrade npm as well but seems that it cannot find v3.10.10 on registry.npmjs.org/npm Do you know which repo should I use? - Lempkin
I use npm 3.8.6 with node 6.11.0 on my maven project I guess you can use both node 6.11.2 and npm 3.8.6... - n00dl3
It cannot find this version either : [ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.5:install-node-and-npm (install node and npm) on project hsmt-angular: Could not download npm: Got error code 500 from the server. -> [Help 1] Did you use a specific repository? - Lempkin
Try without the "v" (extracted from my pom.xml: <nodeVersion>v6.11.0</nodeVersion><npmVersion>3.8.6</npmVersion>) - n00dl3

2 Answers

1
votes

You are using an old version of nodejs and npm, you just need to switch to the version you are using outside of maven.

in a terminal run these commands:

npm --version
node --version

on my computer, these commands outputs v6.11.2 for nodejs and 3.10.10 for npm so the pom.xml should look like this :

<nodeVersion>v6.11.2</nodeVersion>
<npmVersion>3.10.10</npmVersion>
0
votes

actually you don't need a specific frontend plugin for that task.

If in your environment the you're able to run npm run build than you can use the exec-maven-plugin with something like this:

 <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>install npm dependencies</id>
            <phase>initialize</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <workingDirectory>${project.basedir}</workingDirectory>
              <executable>npm</executable>
              <commandlineArgs>install</commandlineArgs>
            </configuration>
          </execution>
          <execution>
            <id>build webapp</id>
            <phase>compile</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <workingDirectory>${project.basedir}</workingDirectory>
              <executable>npm</executable>
              <commandlineArgs>run build</commandlineArgs>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>