首页 > 解决方案 > @NgModule 的意外令牌

问题描述

每当我尝试通过在 cmd 中执行以下命令来运行 webpack

root-path>node-modules\.bin\webpack    

我收到以下错误:

app.module.ts 中 @NgModule 的意外令牌。

似乎它不识别@符号。

我的应用程序的起点是 main.ts。我正在努力使用 angular js 和 angular 5 创建一个混合应用程序

main.ts

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module.ts';
import { environment } from './environments/environment.ts';

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule)
  .catch(err => console.log(err));

app.module.ts

import 'zone.js';
import 'angular';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { UpgradeModule } from '@angular/upgrade/static';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppComponent } from "./app.component";

@NgModule({
 imports: [
    BrowserModule,
    UpgradeModule
  ],
  declarations: [
    AppComponent
  ],

  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { 
constructor(private upgrade:UpgradeModule){}
  ngDoBootstrap() {
    this.upgrade.bootstrap(document.body, ['[config-module]'],{ strictDi: true });
}
}

webpack.config.js

const path = require('path');
//const ngtools = require('@ngtools/webpack');

module.exports = {
  resolve: {
    extensions: ['.ts', '.js'],
    alias: {
      "@angular/upgrade/static": "@angular/upgrade/bundles/upgrade-static.umd.js"
    }
  },
  entry: './src/app/angular6/src/main.ts',
  output: {
    path: path.join(process.cwd(), 'dist'),
    publicPath: 'dist/',
    filename: "bundle.js"
  },


  module: {
    rules: [
        {
        test: /.ts$/,
        exclude:/(node_modules)/,
        use:{
            loader:"babel-loader",
            options:{
                presets:["env"]
            }
        }

      }

    ]
  }


};

tsconfig.js

{
  "compilerOptions": {
    "module": "es2015",
    "moduleResolution": "node",
    "target": "es5",
    "noImplicitAny": false,
    "sourceMap": true,
    "mapRoot": "",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "es2017",
      "dom"
    ],
    "outDir": "lib",
    "skipLibCheck": true,
    "rootDir": "."
  },

标签: angularangular5

解决方案


推荐阅读