2

I am trying to add the copy-webpack-plugin to my asp .net core 2-angular5 web application. I have installed copy-webpack-plugin. I am recieving the following error on running webpack.js :

 new webpack.CopyWebpackPlugin(
        ^
 TypeError: webpack.CopyWebpackPlugin is not a constructor

Here is the webpack.config.js

    const CopyWebpackPlugin = require('copy-webpack-plugin').CopyWebpackPlugin;
    ....
    const clientBundleConfig = merge(sharedConfig, {
    entry: { 'main-client': './ClientApp/boot.browser.ts' },
    output: { path: path.join(__dirname, clientBundleOutputDir) },
    plugins: [
        new webpack.CopyWebpackPlugin(
            { from: './ClientApp/assets', to: './wwwroot/dist/assets', toType : 'dir' }
        ),
        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']
        })
    ])
});

How do I solve this error?

1 Answer 1

2

Please try it with:

const CopyWebpackPlugin = require('copy-webpack-plugin');

I think there is no named export named "CopyWebpackPlugin"

And instatiate it with

new CopyWebpackPlugin([ ...patterns ], options)

Docs: https://github.com/webpack-contrib/copy-webpack-plugin

Explanation:

When you write

new webpack.CopyWebpackPlugin()

You are assuming that webpack comes with the CopyWebpackPlugin and publishes it under its namespace, but webpack doesn't come with CopyWebPackPlugin under its namespace. That is why you have to install and import it separately

Sign up to request clarification or add additional context in comments.

1 Comment

I did try this out before. But it was still providing the same error. I was able to get rid of the error by using serverBundleConfig.plugins.concat instead.

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.