4

Angular 5 aspnetcore 2.0 is my environment.

And I updated my packages to angular 5 and replace AotPlugin to AngularCompilerPlugin in webpack.config.js. while publishing my project, I'm getting this error.

 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

So I revoked this changes and restored AotPlugin in webpack.config.js now my publish got success.

Actually for angular 5 AngularCompilerPlugin used instead of AotPlugin. so my question is did I miss something? what I did wrong here?.

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"
  }
}

As I check while publishing it not taking the updated versions. what would be the reason?

12-07T06:23:03.8757490Z   Web5 -> d:\a\1\s\web5.dll
2017-12-07T06:24:43.8922441Z   [email protected] d:\a\1\s\web\
2017-12-07T06:24:43.8923186Z   +-- @angular/[email protected] 
2017-12-07T06:24:43.8923751Z   +-- @angular/[email protected] 
2017-12-07T06:24:43.8925363Z   +-- @angular/[email protected] 
2017-12-07T06:24:43.8935332Z   +-- @angular/[email protected] 
2017-12-07T06:24:43.8936589Z   | `-- [email protected] 
2017-12-07T06:24:43.8936969Z   +-- @angular/[email protected] 
2017-12-07T06:24:43.8937290Z   +-- @angular/[email protected] 
2017-12-07T06:24:43.8937696Z   +-- @angular/[email protected] 
2017-12-07T06:24:43.8938023Z   +-- @angular/[email protected] 
2017-12-07T06:24:43.8938348Z   +-- @angular/[email protected] 
2017-12-07T06:24:43.8938687Z   +-- @angular/[email protected] 
2017-12-07T06:24:43.8939007Z   +-- @angular/[email protected] 
2017-12-07T06:24:43.8939341Z   +-- @angular/[email protected] 

2 Answers 2

4

Hard to tell without seeing your webpack.config.

This is the way I prefer:

const AotPlugin = require('@ngtools/webpack').AngularCompilerPlugin;

plugins: [
        new AotPlugin({
            tsConfigPath: './tsconfig.json',
            entryModule: path.join(__dirname, 'src/app/app.module#AppModule')
        })
]
Sign up to request clarification or add additional context in comments.

7 Comments

nothing much to show I just replace all AotPlugin to AngularCompilerPlugin in webpack.config rest all remain unchange.
Hard to guess what the original looked like:)
I tried above one still no luck. throwing same error.
What version of @angular/compiler-cli?
just now I found weird one: my dependencies in npm folder all are revert to 4.2.5. how does it happen ? initally I updated all the pavkages run the app checked ther version it is in 5.0.5. later after webapck changes again revert to old versions.
|
1

I have changed version numbers 4.2.x to 5.0.x manually in package.json so it not reflect in package-lock.json, while publishing it taking package-lock.json as consideration in this case I got above error cause angular 4.2 not supports AngularCompilerPlugin. npm >5 version allow me to update both package.json and package-lock.json at a time.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.