这是我的第一篇SO帖子,所以请放轻松我。
我正在尝试使用嵌入在client
文件夹中的Angular 2部署Rails-API应用程序,以便我可以一次性部署整个应用程序。但是,在使用git push heroku master
部署时,构建"成功"虽然该应用程序无法部署。
首先,我将我的Angular客户端应用程序链接到公用文件夹:
$ rm -rf public
$ ln -s client/dist public
然后我添加了以下buildpack:
$ heroku buildpacks:add https://github.com/jasonswett/heroku-buildpack-nodejs
$ heroku buildpacks:add heroku/ruby
这是我的package.json:
{
"name": "my_app",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test",
"pree2e": "webdriver-manager update",
"e2e": "protractor",
"preinstall": "npm install -g node-gyp",
"heroku-postbuild": "ng build"
},
"private": true,
"dependencies": {
"@angular/common": "2.0.0-rc.5",
"@angular/compiler": "2.0.0-rc.5",
"@angular/core": "2.0.0-rc.5",
"@angular/forms": "0.3.0",
"@angular/http": "2.0.0-rc.5",
"@angular/platform-browser": "2.0.0-rc.5",
"@angular/platform-browser-dynamic": "2.0.0-rc.5",
"@angular/router": "3.0.0-rc.1",
"core-js": "^2.4.0",
"rxjs": "5.0.0-beta.11",
"ts-helpers": "^1.1.1",
"zone.js": "0.6.12",
"@types/jasmine": "^2.2.30",
"angular-cli": "1.0.0-beta.11-webpack.8",
"codelyzer": "~0.0.26",
"jasmine-core": "2.4.1",
"jasmine-spec-reporter": "2.5.0",
"karma": "0.13.22",
"karma-chrome-launcher": "0.2.3",
"karma-jasmine": "0.3.8",
"karma-remap-istanbul": "^0.2.1",
"protractor": "4.0.3",
"ts-node": "1.2.1",
"tslint": "3.13.0",
"typescript": "2.0.0",
"awesome-typescript-loader": "2.2.1"
},
"devDependencies": {
}
}
根据this发布帖子的建议,将"awesome-typescript-loader": "2.2.1"
添加到package.json
依赖项也无法解决错误。
仅供参考,我一直在关注Jason Swett关于这个主题的指南:How to Deploy a Rails Application with an Angular CLI Webpack Front-End
git push heroku master
之后的日志的相关部分:
{...}
re34ms emitting
remote: Hash: 8b0f868d8f0eb54b494b
remote: Version: webpack 2.1.0-beta.21
remote: Time: 10807ms
remote: Asset Size Chunks Chunk Names
remote: main.bundle.js 2.51 MB 0, 2 [emitted] main
remote: styles.bundle.js 10.2 kB 1, 2 [emitted] styles
remote: inline.js 5.53 kB 2 [emitted] inline
remote: main.map 3.12 MB 0, 2 [emitted] main
remote: styles.map 14.2 kB 1, 2 [emitted] styles
remote: inline.map 5.59 kB 2 [emitted] inline
remote: index.html 472 bytes [emitted]
remote: chunk {0} main.bundle.js, main.map (main) 2.46 MB {1} [initial] [rendered]
remote: chunk {1} styles.bundle.js, styles.map (styles) 9.96 kB {2} [initial] [rendered]
remote: chunk {2} inline.js, inline.map (inline) 0 bytes [entry] [rendered]
remote:
remote: ERROR in [default] /tmp/build_26074be1021be2d930cc2ecb8ff54a9a/client/src/app/app.component.ts:5:12
remote: Cannot find name 'require'.
remote:
remote: ERROR in [default] /tmp/build_26074be1021be2d930cc2ecb8ff54a9a/client/src/app/app.component.ts:6:11
remote: Cannot find name 'require'.
remote: Child html-webpack-plugin for "index.html":
remote: Asset Size Chunks Chunk Names
remote: index.html 2.81 kB 0
remote: chunk {0} index.html 339 bytes [entry] [rendered]
{...}
为了调试此问题,是否还有其他可能相关的信息?
答案 0 :(得分:1)
"scripts": {
"start": "ng serve --proxy-config proxy.conf.json",
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test",
"pree2e": "webdriver-manager update",
"e2e": "protractor",
"heroku-postbuild": "ng build --prod"
},
添加
“start”:“ng serve --proxy-config proxy.conf.json”,
并且在推送到heroku之前不要忘记提交更改:)