angular - @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": "."
},
解决方案
推荐阅读
- css - Vue-cli 导入 css 不起作用
- excel - ASP 数据导出到 Excel
- scala - 在 Gatling 中为异步调用设置超时
- android - 将嵌套在 ContraintLayout 中的 RecyclerView 膨胀
- windows - 无法从 ACCESS VBA 获得写入桌面的权限
- typescript - Typescript 的 Xmpp 库
- javascript - 如何使用 Javascript/Jquery 自动刷新页面而不闪烁?
- java - 如何通过java jsoup从网页中检索准确的url
- reactjs - React-native - 世博会,在 twitter 上分享
- angularjs - 根据属性值过滤出数组对象 - AngularJS