-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does not work when loaded as an ESM module #84
Comments
Hi, I just wanted to throw it out there that I suffer the same problem as @kirlat above. I use
I have been using this successfully for the past few months now without hiccup. Here's to hoping that somebody with more time might be able to nail this problem in its coffin! :-) Thanks! |
I got exactly the same problem than @kirlat, using ESM, |
I am having the same problem currently and I think the solution is to make the check against webpackDir = module.parent && path.dirname(module.parent.filename); And so the problem is solved. |
Closed via #95 for
|
The plugin works great when loaded as
require('clean-webpack-plugin')
. However, we need to run it in a node.js build script that uses an ESM import syntax, with--experimental-modules
flag (node.js 10). This is how we load it:import CleanWebpackPlugin from 'clean-webpack-plugin'
. Unfortunately, it returns the following error:TypeError: Cannot read property 'filename' of undefined
. I've checked the plugin code, and the only place wherefilename
is used ismodule.parent.filename
. I checked, andmodule.parent
is undefined when plugin is loaded using ESM syntax.What would be the best way to fix this? It seems that
module.parent.filename
is used to determine Webpack location. However, plugin takes aroot
option that is a Webpack root path. Can we check if module.parent is undefined and if it is, use aroot
option instead of it?This plugin is really helpful and I would love to be able to use it in an ESM environment.
The text was updated successfully, but these errors were encountered: