2017-08-25 77 views
1

我使用angular-cli生成了我的angular 2項目。 由於項目和客戶的限制,我無法升級到角度4。angular-cli + mvn:無法啓動構建

我嘗試使用frontend-maven-plugin來編譯我的角度應用與maven,但是當我啓動mvn乾淨安裝時,構建腳本失敗。

我得到了錯誤:

[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

我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> 

我的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" 
    }, 
+1

' V4 .6.0':-o。目前的價格是6.11.2。檢查您在maven之外使用的版本,並將其粘貼到您的pom.xml中。順便說一句這個錯誤只出現在maven中? (我想是的) – n00dl3

+0

偉大的這是與節點v6.11.2 :)(這確實是我的電腦上安裝的版本)我試圖升級npm,但似乎它無法找到v3.10.10在https:/ /registry.npmjs.org/npm/你知道我應該使用哪個回購嗎? – Lempkin

+0

我在我的maven項目中使用npm'3.8.6'節點爲'6.11.0'我猜你可以同時使用節點'6.11.2'和npm'3.8.6' ... – n00dl3

回答

1

您使用的是舊版本的NodeJS和防範機制,你只需要切換到你在maven之外使用的版本。

在終端

運行以下命令:在我的電腦上

npm --version 
node --version 

,這些命令輸出v6.11.2爲的NodeJS和3.10.10爲NPM所以pom.xml應該是這樣的:

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

其實你並不需要一個特定的前端插件任務。

如果在你的環境中你能夠運行NPM運行構建比你可以使用exec-Maven的插件,像這樣的東西:

<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> 
+0

這種方法的問題是可移植性,其他開發人員需要手動管理節點和npm版本。這是一個真正的痛苦,並可能導致不可預知的行爲。前端插件非常棒,因爲它爲您管理節點版本。 – n00dl3

+0

如果你使用package-lock.json/npm-shrinkwrap.json,你不應該有版本問題。鎖定的主要問題是軟件包不是節點版本。但我明白你的觀點。 – rick