ng服务在EC2服务器上不起作用

Log*_*hen 2 web-hosting amazon-ec2 amazon-web-services angular

我对使用Angular2创建的网站有疑问.我用Angular CLI构建了框架.我已经在我的本地机器上进行了彻底的测试,它完美无缺.端口4200上的"ng serve"主机,整个页面加载并按预期运行.我的所有文件都通过了ts lint.我跑了"ng lint"并没有收到任何警告或错误.

但是,当我将其上传到我的服务器时,"ng serve"将无法正常工作.我的服务器是通过Amazon Web Services(AWS)在EC2节点上创建的Bitnami映像.我将nodejs,npm和Angular CLI安装到服务器并检查以确保版本是最新的.所有这些都是.

当我第一次尝试"ng serve"命令时,我收到了这个错误:

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"
Run Code Online (Sandbox Code Playgroud)

我更改了我的angular-cli.json以反映"After:"部分并再次运行"ng serve"命令.(我不认为这是问题,但我认为这是相关信息).

目前的错误是这样的:

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
Run Code Online (Sandbox Code Playgroud)

据我所知,我的main.ts和polyfill.ts文件中都有一些newLine字符.我看了他们一眼,什么都没发现.我没有更改任何一个文件.这些文件是由角度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);
Run Code Online (Sandbox Code Playgroud)

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';
Run Code Online (Sandbox Code Playgroud)

谢谢您的帮助!

小智 9

如果上面的错误仍然存​​在,那么试试这个:希望它有效.

打开angular-cli.json找到 -

"environments":{"source":"environments/environment.ts","dev":"environments/environment.ts","prod":"environments/environment.prod.ts"}

并替换为:

"environmentSource":"environments/environment.ts","environment":{"dev":"environments/environment.ts","prod":"environments/environment.prod.ts"}


Jas*_*ana 5

Rj-s的解决方案对我有用.运行npm install -g @angular/cli以全局安装,然后npm install @angular/cli在本地安装.这是在确定你不再引用旧angular-cli包装之后.