我遇到了使用Angular2創建的網站的問題。我使用Angular CLI構建了框架。我在本地機器上進行了徹底測試,效果非常好。 「ng服務」端口4200上的主機,並且整個頁面按其應該加載和運行。我的所有文件都通過ts lint。我運行「ng lint」並沒有收到任何警告或錯誤。ng服務將無法在EC2服務器上工作
但是,當我上傳到我的服務器「ng服務」將無法正常工作。我的服務器是通過Amazon Web Services(AWS)在EC2節點上創建的Bitnami映像。我在服務器上安裝了nodejs,npm和Angular CLI,並進行了檢查以確保版本是最新的。他們都是。
當我第一次嘗試了「NG服務」命令,我得到這個錯誤:
Environment configuration does not contain "environmentSource" entry.
A new environmentSource entry replaces the previous source entry inside environments.
To migrate angular-cli.json follow the example below:
Before:
"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
After:
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
我改變了我的角cli.json體現「之後:」部分,跑了「NG服務」命令再次。 (我不認爲這是問題,但我認爲這是相關信息)。
的當前錯誤是這樣的:
ERROR in ./src/main.ts
Module build failed: TypeError: Cannot read property 'newLine' of undefined
at Object.getNewLineCharacter (/opt/bitnami/apache2/htdocs/Logan/ProjX-Eng316/node_modules/typescript/lib/typescript.js:8062:20)
at Object.createCompilerHost (/opt/bitnami/apache2/htdocs/Logan/ProjX-Eng316/node_modules/typescript/lib/typescript.js:44978:26)
at Object.ngcLoader (/opt/bitnami/apache2/htdocs/Logan/ProjX-Eng316/node_modules/@ngtools/webpack/src/loader.js:350:33)
@ multi webpack-dev-server/client?http://localhost:4200/ ./src/main.ts
ERROR in ./src/polyfills.ts
Module build failed: TypeError: Cannot read property 'newLine' of undefined
at Object.getNewLineCharacter (/opt/bitnami/apache2/htdocs/Logan/ProjX-Eng316/node_modules/typescript/lib/typescript.js:8062:20)
at Object.createCompilerHost (/opt/bitnami/apache2/htdocs/Logan/ProjX-Eng316/node_modules/typescript/lib/typescript.js:44978:26)
at Object.ngcLoader (/opt/bitnami/apache2/htdocs/Logan/ProjX-Eng316/node_modules/@ngtools/webpack/src/loader.js:350:33)
@ multi ./src/polyfills.ts
據我可以告訴有我main.ts和我polyfill.ts文件都有些換行符。我看過他們,什麼都沒發現。我沒有更改任何文件。這些文件是由角度cli生成的,我不太喜歡自己修改它們。
如何解決這些錯誤?我需要更新包嗎?我是否需要更改我的polyfill和主打字稿文件?
下面是這些文件,如果你需要看他們過來:
main.ts:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { environment } from './environments/environment';
import { AppModule } from './app/app.module';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule);
polyfills.ts:
// This file includes polyfills needed by Angular and is loaded before the app.
// You can add your own extra polyfills to this file.
import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es6/function';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
import 'core-js/es6/date';
import 'core-js/es6/array';
import 'core-js/es6/regexp';
import 'core-js/es6/map';
import 'core-js/es6/set';
import 'core-js/es6/reflect';
import 'core-js/es7/reflect';
import 'zone.js/dist/zone';
// If you need to support the browsers/features below, uncomment the import
// and run `npm install import-name-here';
// Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
// Needed for: IE9
// import 'classlist.js';
// Animations
// Needed for: All but Chrome and Firefox, Not supported in IE9
// import 'web-animations-js';
// Date, currency, decimal and percent pipes
// Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
// import 'intl';
// NgClass on SVG elements
// Needed for: IE10, IE11
// import 'classlist.js';
感謝您的幫助!
納克服務是一個開發Web服務器。它不應該用於生產。使用'ng build [--prod]',並使用真實的生產Web服務器來爲dist目錄中生成的靜態文件提供服務。你不需要節點(除非你的後端被寫入節點),服務器上的npm和angular-cli。 –
謝謝,我將使用ng build。不過,我仍然有時使用這臺服務器進行開發。我真的很想能夠使用ng服務來達到這個目的。 –
我面臨同樣的問題,但通過在全球和本地升級angular-cli得到解決。 –