当我在localhost上本地运行它时,ng build --aot --prod运行没有问题,但是当我在heroku上部署时,它不再识别组件的导入。它表示package.json中可能缺少依赖项,但是我按照本指南的建议添加了devDependencies的所有依赖项 https://itnext.io/how-to-deploy-angular-application-to-heroku-1d56e09c5147。
我查看并尝试了许多发现可以研究的解决方案,但到目前为止没有任何工作。我真的不知道从哪里开始调试此问题,将不胜感激
edit:放弃尝试修复它,所以我只是创建了一个新的Angular项目,并且只是在src上复制并更改了新的应用程序package.json,现在它可以了,所以我不知道问题出在哪里实在太沮丧了,无法解决。
package.json:
{
"name": "event-app",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "node server.js",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"postinstall": "ng build --aot --prod"
},
"private": true,
"dependencies": {
"@angular/animations": "~8.2.14",
"@angular/cli": "~8.3.20",
"@angular/common": "~8.2.14",
"@angular/compiler": "~8.2.14",
"@angular/compiler-cli": "~8.2.14",
"@angular/core": "~8.2.14",
"@angular/forms": "~8.2.14",
"@angular/platform-browser": "~8.2.14",
"@angular/platform-browser-dynamic": "~8.2.14",
"@angular/router": "~8.2.14",
"@material-ui/pickers": "^3.2.8",
"@ng-bootstrap/ng-bootstrap": "^5.1.4",
"bootstrap": "^4.4.1",
"dotenv": "^8.2.0",
"enhanced-resolve": "^4.1.1",
"express": "^4.17.1",
"jquery": "^3.4.1",
"rxjs": "~6.4.0",
"rxjs-compat": "^6.5.3",
"tree-kill": "^1.2.2",
"tslib": "^1.10.0",
"typescript": "~3.5.3",
"zone.js": "~0.9.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.803.22",
"@angular/language-service": "~8.2.14",
"@angular/cli": "~8.3.20",
"@angular/compiler-cli": "~8.2.14",
"@types/jasmine": "~3.3.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "^5.0.0",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.15.0",
"typescript": "~3.5.3"
},
"engines": {
"node": "10.16.3",
"npm": "6.9.0"
}
}
CLI:
PS C:\Users\Frank\Documents\GitHub\angular-test\lostnFound> git push heroku master
Enumerating objects: 223, done.
Counting objects: 100% (223/223), done.
Delta compression using up to 8 threads
Compressing objects: 100% (218/218), done.
Writing objects: 100% (223/223), 174.83 KiB | 3.43 MiB/s, done.
Total 223 (delta 117), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_LOGLEVEL=error
remote: NODE_ENV=production
remote: NODE_MODULES_CACHE=false
remote: NODE_VERBOSE=false
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): 10.16.3
remote: engines.npm (package.json): 6.9.0
remote:
remote: Resolving node version 10.16.3...
remote: Downloading and installing node 10.16.3...
remote: npm 6.9.0 already installed with node
remote:
remote: -----> Restoring cache
remote: Caching has been disabled because NODE_MODULES_CACHE=false
remote:
remote: -----> Installing dependencies
remote: Installing node modules (package.json + package-lock)
remote:
remote: > core-js@2.6.11 postinstall /tmp/build_88602988e915eee083edd9f087d17ec5/node_modules/babel-runtime/node_modules/core-js
remote: > node -e "try{require('./postinstall')}catch(e){}"
remote:
remote:
remote: > core-js@3.2.1 postinstall /tmp/build_88602988e915eee083edd9f087d17ec5/node_modules/core-js
remote: > node scripts/postinstall || echo "ignore"
remote:
remote:
remote: > core-js-pure@3.4.7 postinstall /tmp/build_88602988e915eee083edd9f087d17ec5/node_modules/core-js-pure
remote: > node -e "try{require('./postinstall')}catch(e){}"
remote:
remote:
remote: > core-js@2.6.10 postinstall /tmp/build_88602988e915eee083edd9f087d17ec5/node_modules/karma/node_modules/core-js
remote: > node postinstall || echo "ignore"
remote:
remote:
remote: > @angular/cli@8.3.20 postinstall /tmp/build_88602988e915eee083edd9f087d17ec5/node_modules/@angular/cli
remote: > node ./bin/postinstall/script.js
remote:
remote:
remote: > event-app@0.0.0 postinstall /tmp/build_88602988e915eee083edd9f087d17ec5
remote: > ng build --aot --prod
remote:
remote:
remote: ERROR in src/app/app-routing.module.ts:3:32 - error TS2307: Cannot find module './posts/posts.component'.
remote:
remote: 3 import { PostsComponent } from './posts/posts.component';
remote: ~~~~~~~~~~~~~~~~~~~~~~~~~
remote: src/app/app.module.ts:10:32 - error TS2307: Cannot find module './posts/posts.component'.
remote:
remote: 10 import { PostsComponent } from './posts/posts.component';
remote: ~~~~~~~~~~~~~~~~~~~~~~~~~
remote:
remote: ERROR in src/app/app.module.ts(23,5): Error during template compile of 'AppModule'
remote: Could not resolve ./posts/posts.component relative to [object Object]..
remote: src/app/app-routing.module.ts(11,25): Error during template compile of 'AppRoutingModule'
remote: Could not resolve ./posts/posts.component relative to [object Object]..
remote: src/app/app-routing.module.ts(14,30): Error during template compile of 'AppRoutingModule'
remote: Could not resolve ./posts/posts.component relative to [object Object]..
remote: Couldn't resolve resource ./posts.component.css relative to /tmp/build_88602988e915eee083edd9f087d17ec5/src/app/Posts/posts.component.ts
remote:
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! event-app@0.0.0 postinstall: `ng build --aot --prod`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the event-app@0.0.0 postinstall script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.PK91A/_logs/2020-01-14T02_44_41_751Z-debug.log
remote:
remote: -----> Build failed
remote:
remote: We're sorry this build is failing! You can troubleshoot common issues here:
remote: https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote: Some possible problems:
remote:
remote: - A module may be missing from 'dependencies' in package.json
remote: https://devcenter.heroku.com/articles/troubleshooting-node-deploys#ensure-you-aren-t-relying-on-untracked-dependencies
remote:
remote: Love,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Node.js app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote: