2017-02-16 55 views
0

我有一個terraform腳本來站起來一個EC2實例,它安裝git,nvm,node,並從github安裝一個angular2倉庫。Terraform user_data ng build

# install angular cli globally 
npm install -g @angular/cli &> globalCli.log 
cd test 
# install node_modules 
npm install &> npmInstall.log 
# create dist folder 
ng build --output-path 'dist' >& ngBuild.log 
ng update >& ngUpdate.log 
#start the app 
(npm start) &> npmStart.log``` 

出於某種原因,terrform腳本返回該錯誤ngBuild.log

Path must be a string. Received undefined 
TypeError: Path must be a string. Received undefined 
at assertPath (path.js:7:11) 
at Object.join (path.js:1211:7) 
at Function.fromProject (/test/node_modules/@angular/cli/models/config.js:53:39) 
at Object.<anonymous> (/test/node_modules/@angular/cli/commands/serve.js:11:35) 
at Module._compile (module.js:571:32) 
at Object.Module._extensions..js (module.js:580:10) 
at Module.load (module.js:488:32) 
at tryModuleLoad (module.js:447:12) 
at Function.Module._load (module.js:439:3) 
at Module.require (module.js:498:17) 
at require (internal/module.js:20:19) 
at Class.includedCommands (/test/node_modules/@angular/cli/addon/index.js:23:16) 
at /test/node_modules/@angular/cli/ember-cli/lib/models/project.js:326:61 
at Array.forEach (native) 
at Project.addonCommands (/test/node_modules/@angular/cli/ember-cli/lib/models/project.js:325:15) 
at Project.eachAddonCommand (/test/node_modules/@angular/cli/ember-cli/lib/models/project.js:360:30) 
at module.exports (/test/node_modules/@angular/cli/ember-cli/lib/cli/lookup-command.js:33:13) 
at CLI.<anonymous> (/test/node_modules/@angular/cli/ember-cli/lib/cli/cli.js:42:26) 
at tryCatch (/fsi-ui/node_modules/rsvp/dist/rsvp.js:538:12) 
at invokeCallback (/test/node_modules/rsvp/dist/rsvp.js:553:13) 
at publish (/test/node_modules/rsvp/dist/rsvp.js:521:7) 
at flush (/test/node_modules/rsvp/dist/rsvp.js:2373:5) 
at _combinedTickCallback (internal/process/next_tick.js:67:7) 
at process._tickCallback (internal/process/next_tick.js:98:9) 

奇怪的是,如果我ssh到EC2實例,並運行相同的ng build命令,它工作正常。

任何想法?

回答

0

如果有其他人遇到這個問題(我搜索試圖找到答案,並找不到解決我的問題的人)。

最終,它歸結爲@ angular/cli版本問題。當我在ec2實例內部手動運行ng build時,我發現全球cli和本地cli之間存在差異。我更新了package.json以使用latest,然後必須將以下內容添加到我的angular-cli.json文件"environmentSource": "environments/environment.ts"

我輸出的日誌仍然說路徑需要一個字符串,但我相信這只是一個腳本問題,通過terraform出現。 /dist/安裝成功!