shellscape / webpack-manifest-plugin

webpack plugin for generating asset manifests
MIT License
1.44k stars 185 forks source link

TypeError: ManifestPlugin is not a constructor #232

Closed mizziness closed 3 years ago

mizziness commented 3 years ago

(Note: the above repro is an exact copypasta of my local project, however, I get a the same thing with a minimal build, so I am able to rule out my other plugins and config. A link to that super minimal repo is: https://repl.it/@mizziness/manifest-plugin-repro-1#package.json )

Expected Behavior

I expect to be able to run basic webpack commands without error.

Actual Behavior

Webpack commands, such as webpack --mode development result in the error: [webpack-cli] TypeError: ManifestPlugin is not a constructor

Additional Information

Local stack trace using yarn:

yarn run v1.22.5
$ webpack --mode development
[webpack-cli] TypeError: ManifestPlugin is not a constructor
    at Object.<anonymous> (/Applications/MAMP/help.applause.com/webpack.config.js:79:5)
    at Module._compile (/Applications/MAMP/help.applause.com/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
    at Module.load (internal/modules/cjs/loader.js:812:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Module.require (internal/modules/cjs/loader.js:849:19)
    at require (/Applications/MAMP/help.applause.com/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at requireConfig (/Applications/MAMP/help.applause.com/node_modules/webpack-cli/lib/groups/resolveConfig.js:73:18)
    at Array.map (<anonymous>)
    at resolveConfigFiles (/Applications/MAMP/help.applause.com/node_modules/webpack-cli/lib/groups/resolveConfig.js:124:40)
error Command failed with exit code 2.

Workaround:

Currently, using webpack-manifest-plugin@^2.0.3 will allow me to build correctly.

mizziness commented 3 years ago

Addendum:

I thought originally that using webpack-cli might be the issue, and instead swapped it out for webpack-nano, but the same error occurs:

$ yarn wp dev
yarn run v1.22.5
$ wp dev
TypeError: ManifestPlugin is not a constructor
    at Object.<anonymous> (/Applications/MAMP/help.applause.com/webpack.config.js:79:5)
    at Module._compile (internal/modules/cjs/loader.js:956:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
    at Module.load (internal/modules/cjs/loader.js:812:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Module.require (internal/modules/cjs/loader.js:849:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at loadConfig (/Applications/MAMP/help.applause.com/node_modules/webpack-nano/lib/config.js:86:24)
    at doeet (/Applications/MAMP/help.applause.com/node_modules/webpack-nano/bin/wp.js:78:24)
    at Object.<anonymous> (/Applications/MAMP/help.applause.com/node_modules/webpack-nano/bin/wp.js:88:28)
error Command failed with exit code 1.

I then thought that maybe going back to webpack 4 might work, but swapping out for webpack@4.44.2 also results in the same error.

erik-perri commented 3 years ago

There is no longer a default export, try changing the require to

const { WebpackManifestPlugin } = require('webpack-manifest-plugin');

(and switch ManifestPlugin with WebpackManifestPlugin in the webpack config)

shellscape commented 3 years ago

Always read the documentation again after updating major versions: https://github.com/shellscape/webpack-manifest-plugin#usage

mizziness commented 3 years ago

@shellscape Side note: The replication project is still running the old method from version 2 :) It would be helpful to have the above syntax used there.

shellscape commented 3 years ago

Thanks for the heads up, I'll get right on that

shellscape commented 3 years ago

Updated!

shwao commented 3 years ago

@shellscape Thanks for your work. But this is a breaking change that should be listed in the release note.

shellscape commented 3 years ago

It's in the README. Always read the docs when upgrading majors.

shellscape commented 3 years ago

@shwao I've removed your rude comment. You're welcome to use an alternative, and given your attitude, I suggest you do. This is your only warning, further rudeness will result in a block.