ng build --prod 在本地工作,但在从 ngx-bootstrap 添加模态后在远程服务器上失败

ng build --prod works local but fails on remote server after adding Modal from ngx-bootstrap

基本上是标题:我在我的机器上 运行 ng build --prod 并且它工作正常,但是当我在服务器上 运行 它失败了。这在我从 ngx-bootstrap 导入模态后开始发生。我的服务器是 运行ning Debian 9,我的电脑是 运行ning Windows 10。我不知道它会是什么,显然我是唯一遇到这个问题的人。如果有人能帮助我,我将不胜感激。

服务器 (Debian 9) 版本:

Angular CLI: 1.7.0
Node: 6.13.0
OS: linux x64
Angular: 5.2.5
... common, compiler, compiler-cli, core, forms, http
... language-service, platform-browser, platform-browser-dynamic
... router

@angular/animations: 5.2.9
@angular/cli: 1.7.0
@angular-devkit/build-optimizer: 0.3.1
@angular-devkit/core: 0.3.1
@angular-devkit/schematics: 0.3.1
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.0
@schematics/angular: 0.3.1
@schematics/package-update: 0.3.1
typescript: 2.4.2
webpack: 3.11.0

本地(Windows 10)版本:

Angular CLI: 1.6.5
Node: 6.11.5
OS: win32 x64
Angular: 5.2.1
... common, compiler, compiler-cli, core, forms, http
... language-service, platform-browser, platform-browser-dynamic
... router

@angular/animations: 5.2.9
@angular/cli: 1.6.5
@angular-devkit/build-optimizer: 0.0.41
@angular-devkit/core: 0.0.28
@angular-devkit/schematics: 0.0.51
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.5
@schematics/angular: 0.1.16
typescript: 2.4.2
webpack: 3.10.0

ng build --prod

的服务器输出
Date: 2018-04-05T14:30:48.865Z
Hash: bc360d34074ce9195f7c
Time: 13231ms
chunk {0} styles.61225cddb1f29594962b.bundle.css (styles) 153 kB [initial] [rendered]
chunk {1} polyfills.997d8cc03812de50ae67.bundle.js (polyfills) 84 bytes [initial] [rendered]
chunk {2} main.ee32620ecd1edff94184.bundle.js (main) 84 bytes [initial] [rendered]
chunk {3} inline.318b50c57b4eba3d437b.bundle.js (inline) 796 bytes [entry] [rendered]

ERROR in app/app.module.ts(44,5): Error during template compile of 'AppModule'
  Could not resolve @ng-bootstrap relative to /root/moreiaqui/src/app/app.module.ts..
src/app/mapa/mapa.component.ts(21,32): error TS2307: Cannot find module 'ngx-bootstrap/modal'.
src/app/mapa/mapa.component.ts(22,28): error TS2307: Cannot find module 'ngx-bootstrap/modal/bs-modal-ref.service'.
src/app/app.module.ts(14,29): error TS2307: Cannot find module '@ng-bootstrap'.

ng build --prod

的本地输出
Date: 2018-04-05T14:33:46.382Z
Hash: 5550606bfa97f9316f2d
Time: 75043ms
chunk {0} polyfills.f20484b2fa4642e0dca8.bundle.js (polyfills) 59.4 kB [initial] [rendered]
chunk {1} main.99dc4606f1a7fa108dab.bundle.js (main) 694 kB [initial] [rendered]
chunk {2} styles.661f3e21c40c04c28a5f.bundle.css (styles) 153 kB [initial] [rendered]
chunk {3} inline.92305ea719a607a13034.bundle.js (inline) 1.45 kB [entry] [rendered]

我的app.module.ts:

import { BrowserModule } from '@angular/platform-browser';

import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';

import { MyDatePickerModule } from 'mydatepicker';

import { HttpClientModule } from '@angular/common/http';
import { CommonModule } from '@angular/common';
import { AgmCoreModule } from '@agm/core';
import { GoogleMapsAPIWrapper } from '@agm/core';

import { NgbModule } from "@ng-bootstrap/ng-bootstrap";
import { ModalModule } from 'ngx-bootstrap/modal';

import { AppComponent } from './app.component';
import { AppRoutingModule } from './/app-routing.module';
import { HomeComponent } from './home/home.component';
import { EnderecoComponent } from './endereco/endereco.component';
import { MapaComponent } from './mapa/mapa.component';

import {EnderecoService} from './services/data/endereco.service'
import {ReferenciaService} from './services/data/referencia.service'
import {MoradorService} from './services/data/morador.service'
import {AuthService} from './services/data/auth.service'

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ToastrModule } from 'ngx-toastr';
import { HeaderComponent } from './header/header.component';
import { CadastroComponent } from './cadastro/cadastro.component';


@NgModule({
  declarations: [
    AppComponent,
    HomeComponent,
    EnderecoComponent,
    MapaComponent,
    HeaderComponent,
    CadastroComponent
  ],
  imports: [
    MyDatePickerModule,
    ModalModule.forRoot(),
    BrowserModule,
    FormsModule,
    AppRoutingModule,
    HttpClientModule,
    AgmCoreModule.forRoot({
      apiKey: 'AIzaSyCOpkFkFSO1Y_9JjGgxjReFU_k3jLQaUXU',
      libraries: ["places"]
    }),
    BrowserAnimationsModule,
    ToastrModule.forRoot({
      timeOut: 10000,
      positionClass: 'toast-bottom-center',
      preventDuplicates: true,
    }),
    NgbModule.forRoot(),
  ],
  providers: [
    EnderecoService,
    ReferenciaService,
    MoradorService,
    AuthService
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

mapa.component.ts 导入:(我使用模态的组件)

import { Component, OnInit, TemplateRef  } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Location } from '@angular/common';

import { MapsAPILoader } from '@agm/core';
import { AgmMap } from '@agm/core';
import {} from '@types/googlemaps';
import { ViewChild, ElementRef, NgZone } from '@angular/core';

import { EnderecoService } from '../services/data/endereco.service';
import { ReferenciaService } from '../services/data/referencia.service';
import { AuthService } from '../services/data/auth.service';

import { marker } from '../interfaces.model'
import { endereco } from '../interfaces.model'
import { referencia } from '../interfaces.model'

import {IMyDpOptions, IMyDateModel} from 'mydatepicker';
import { ToastrService } from 'ngx-toastr';

import { BsModalService } from 'ngx-bootstrap/modal';
import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service';

my package.json(本地和服务器):

{
  "name": "moreiaqui",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@agm/core": "^1.0.0-beta.2",
    "@angular/animations": "^5.2.9",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/router": "^5.0.0",
    "@ng-bootstrap/ng-bootstrap": "^1.0.4",
    "bootstrap": "^4.0.0",
    "core-js": "^2.4.1",
    "font-awesome": "^4.7.0",
    "jquery": "^1.9.1",
    "mydatepicker": "^2.6.3",
    "ngx-toastr": "^8.3.0",
    "popper.js": "^1.12.9",
    "rxjs": "^5.5.2",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "^1.6.1",
    "@angular/compiler-cli": "^5.0.0",
    "@angular/language-service": "^5.0.0",
    "@types/googlemaps": "^3.30.4",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "~2.4.2"
  }
}

编辑添加 package.json

您的项目中的 ng-bootstrapngx-bootstrap 之间似乎存在冲突,根据您的 app.module

中的以下导入
import { NgbModule } from "@ng-bootstrap/ng-bootstrap"; 

它应该是 ngx-bootstrap 如果你使用 bootstrap 3 否则你必须使用 ng-bootstrap 因为 bootstrap 4.you 不能同时使用它们在同一时间。删除 node_modules 文件夹更新你的 package.json 并使用 ngx-bootstrap.

进行全新的 npm 安装