2017-02-16 67 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/安装成功!