Angular 5 TypeError:AngularCompilerPlugin不是构造函数

时间:2017-12-07 08:15:24

标签: angular asp.net-core asp.net-core-mvc

Angular 5 aspnetcore 2.0是我的环境。

我将我的软件包更新为angular 5,并将AotPlugin替换为AngularCompilerPlugin中的webpack.config.js。在发布我的项目时,我收到了这个错误。

 TypeError: AngularCompilerPlugin is not a constructor
2017-12-07T06:25:19.8388691Z       at module.exports (d:\a\1\s\web\source\webpack.config.js:48:13)
2017-12-07T06:25:19.8388916Z       at requireConfig (d:\a\1\s\web\source\node_modules\webpack\bin\convert-argv.js:102:15)
2017-12-07T06:25:19.8389187Z       at d:\a\1\s\web\source\node_modules\webpack\bin\convert-argv.js:109:17
2017-12-07T06:25:19.8389479Z       at Array.forEach (native)
2017-12-07T06:25:19.8389687Z       at module.exports (d:\a\1\s\web\source\node_modules\webpack\bin\convert-argv.js:107:15)
2017-12-07T06:25:19.8389914Z       at Object.<anonymous> (d:\a\1\s\web\source\node_modules\webpack\bin\webpack.js:153:40)
2017-12-07T06:25:19.8390154Z       at Module._compile (module.js:570:32)
2017-12-07T06:25:19.8390340Z       at Object.Module._extensions..js (module.js:579:10)
2017-12-07T06:25:19.8390524Z       at Module.load (module.js:487:32)
2017-12-07T06:25:19.8390881Z       at tryModuleLoad (module.js:446:12)
2017-12-07T06:25:19.8569143Z d:\a\1\s\web\source\CA.IDM.PAdmin.Web.csproj(41,5): error MSB3073: The command "node node_modules/webpack/bin/webpack.js --env.prod" exited with code 1.
2017-12-07T06:25:19.9453100Z ##[error]Error: C:\Program Files\dotnet\dotnet.exe failed with return code: 1
2017-12-07T06:25:19.9454881Z ##[error]Dotnet command failed with non-zero exit code on the following projects : d:\a\1\s\web\source\CA.IDM.PAdmin.Web.csproj

所以我撤消了此更改,并在AotPlugin中恢复了webpack.config.js,现在我的发布成功了。

实际上,使用角度5 AngularCompilerPlugin代替AotPlugin。所以我的问题是我错过了什么?我在这里做错了什么?。

webpack.config.js

const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const AngularCompilerPlugin = require('@ngtools/webpack').AngularCompilerPlugin ;
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;

module.exports = (env) => {
    // Configuration in common to both client-side and server-side bundles
    const isDevBuild = !(env && env.prod);
    const sharedConfig = {
        stats: { modules: false },
        context: __dirname,
        resolve: { extensions: [ '.js', '.ts' ] },
        output: {
            filename: '[name].js',
            publicPath: 'dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix
        },
        module: {
            rules: [
                { test: /\.ts$/, use: isDevBuild ? ['awesome-typescript-loader?silent=true', 'angular2-template-loader', 'angular2-router-loader'] : '@ngtools/webpack' },
                { test: /\.html$/, use: 'html-loader?minimize=false' },
                { test: /\.css$/, use: [ 'to-string-loader', isDevBuild ? 'css-loader' : 'css-loader?minimize' ] },
                { test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' }
            ]
        },
        plugins: [new CheckerPlugin()]
    };

    // Configuration for client-side bundle suitable for running in browsers
    const clientBundleOutputDir = './wwwroot/dist';
    const clientBundleConfig = merge(sharedConfig, {
        entry: { 'main-client': './ClientApp/boot.browser.ts' },
        output: { path: path.join(__dirname, clientBundleOutputDir) },
        plugins: [
            new webpack.DllReferencePlugin({
                context: __dirname,
                manifest: require('./wwwroot/dist/vendor-manifest.json')
            })
        ].concat(isDevBuild ? [
            // Plugins that apply in development builds only
            new webpack.SourceMapDevToolPlugin({
                filename: '[file].map', // Remove this line if you prefer inline source maps
                moduleFilenameTemplate: path.relative(clientBundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
            })
        ] : [
            // Plugins that apply in production builds only
            new webpack.optimize.UglifyJsPlugin(),
            new AngularCompilerPlugin ({
                tsConfigPath: './tsconfig.json',
                entryModule: path.join(__dirname, 'ClientApp/app/app.browser.module#AppModule'),
                exclude: ['./**/*.server.ts']
            })
        ])
    });

    // Configuration for server-side (prerendering) bundle suitable for running in Node
    const serverBundleConfig = merge(sharedConfig, {
        resolve: { mainFields: ['main'] },
        entry: { 'main-server': './ClientApp/boot.server.ts' },
        plugins: [
            new webpack.DllReferencePlugin({
                context: __dirname,
                manifest: require('./ClientApp/dist/vendor-manifest.json'),
                sourceType: 'commonjs2',
                name: './vendor'
            })
        ].concat(isDevBuild ? [] : [
            // Plugins that apply in production builds only
            new AngularCompilerPlugin ({
                tsConfigPath: './tsconfig.json',
                entryModule: path.join(__dirname, 'ClientApp/app/app.server.module#AppModule'),
                exclude: ['./**/*.browser.ts']
            })
        ]),
        output: {
            libraryTarget: 'commonjs',
            path: path.join(__dirname, './ClientApp/dist')
        },
        target: 'node',
        devtool: 'inline-source-map'
    });

    return [clientBundleConfig, serverBundleConfig];
};

的package.json

{
  "name": "Web5",
  "private": true,
  "version": "0.0.0",
  "scripts": {
    "test": "karma start ClientApp/test/karma.conf.js"
  },
  "devDependencies": {
    "@angular/animations": "5.0.5",
    "@angular/common": "5.0.5",
    "@angular/compiler": "5.0.5",
    "@angular/compiler-cli": "5.0.5",
    "@angular/core": "5.0.5",
    "@angular/forms": "5.0.5",
    "@angular/http": "5.0.5",
    "@angular/platform-browser": "5.0.5",
    "@angular/platform-browser-dynamic": "5.0.5",
    "@angular/platform-server": "5.0.5",
    "@angular/router": "5.0.5",
    "@ngtools/webpack": "1.8.5",
    "@types/chai": "4.0.1",
    "@types/jasmine": "2.5.53",
    "@types/webpack-env": "1.13.0",
    "angular2-router-loader": "0.3.5",
    "angular2-template-loader": "0.6.2",
    "aspnet-prerendering": "^3.0.1",
    "aspnet-webpack": "^2.0.1",
    "awesome-typescript-loader": "3.2.1",
    "bootstrap": "3.3.7",
    "chai": "4.0.2",
    "css": "2.2.1",
    "css-loader": "0.28.4",
    "es6-shim": "0.35.3",
    "event-source-polyfill": "0.0.9",
    "expose-loader": "0.7.3",
    "extract-text-webpack-plugin": "2.1.2",
    "file-loader": "0.11.2",
    "html-loader": "0.4.5",
    "isomorphic-fetch": "2.2.1",
    "jasmine-core": "2.6.4",
    "jquery": "3.2.1",
    "json-loader": "0.5.4",
    "karma": "1.7.0",
    "karma-chai": "0.1.0",
    "karma-chrome-launcher": "2.2.0",
    "karma-cli": "1.0.1",
    "karma-jasmine": "1.1.0",
    "karma-webpack": "2.0.3",
    "preboot": "4.5.2",
    "raw-loader": "0.5.1",
    "reflect-metadata": "0.1.10",
    "rxjs": "5.5.4",
    "style-loader": "0.18.2",
    "to-string-loader": "1.1.5",
    "typescript": "2.6.2",
    "url-loader": "0.5.9",
    "webpack": "2.5.1",
    "webpack-hot-middleware": "2.18.2",
    "webpack-merge": "4.1.0",
    "zone.js": "0.8.12"
  }
}

我在发布时检查时没有采用更新版本。会是什么原因?

12-07T06:23:03.8757490Z   Web5 -> d:\a\1\s\web5.dll
2017-12-07T06:24:43.8922441Z   Web5@0.0.0 d:\a\1\s\web\
2017-12-07T06:24:43.8923186Z   +-- @angular/animations@4.2.5 
2017-12-07T06:24:43.8923751Z   +-- @angular/common@4.2.5 
2017-12-07T06:24:43.8925363Z   +-- @angular/compiler@4.2.5 
2017-12-07T06:24:43.8935332Z   +-- @angular/compiler-cli@4.2.5 
2017-12-07T06:24:43.8936589Z   | `-- minimist@1.2.0 
2017-12-07T06:24:43.8936969Z   +-- @angular/core@4.2.5 
2017-12-07T06:24:43.8937290Z   +-- @angular/forms@4.2.5 
2017-12-07T06:24:43.8937696Z   +-- @angular/http@4.2.5 
2017-12-07T06:24:43.8938023Z   +-- @angular/platform-browser@4.2.5 
2017-12-07T06:24:43.8938348Z   +-- @angular/platform-browser-dynamic@4.2.5 
2017-12-07T06:24:43.8938687Z   +-- @angular/platform-server@4.2.5 
2017-12-07T06:24:43.8939007Z   +-- @angular/router@4.2.5 
2017-12-07T06:24:43.8939341Z   +-- @angular/tsc-wrapped@4.2.5 

2 个答案:

答案 0 :(得分:3)

很难说没有看到你的webpack.config。

这是我喜欢的方式:

Adelaide:AU.MWWN07rEfU

答案 1 :(得分:1)

我已在package.json中手动将版本号4.2.x更改为5.0.x,因此它不会反映在package-lock.json中,而在发布它时将package-lock.json作为考虑因素在这种情况下我得到了错误原因角度4.2不支持AngularCompilerPlugin。 npm&gt; 5版本允许我一次更新package.json和package-lock.json。