-
Notifications
You must be signed in to change notification settings - Fork 20
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
plugin-webpack-filter; Documentation; Importing into ESM #4630
Comments
@SStranks thank you for opening an issue! Can you please share your version of Node and whether the module you are trying to import is ESM or Typescript? I was able to replicate your error by using an import inside an esm config file ( |
I'm using Node v.20.9.0. I was importing the package into my webpack config file (.js) - my package.json has "type" set to "module". It's a TypeScript (v5.3.3) project; the webpack configs are using I'm interested in understanding all this, so any insights or information on the whole thing would be appreciated :) |
@SStranks i released a fix for it in The current stable ships commonjs and esm in ".js" files and only sets "module" property in package.json. Bundlers are able to load the correct format, but node is not able to load the esm format:
More resources:
We have an update that publishes correct mjs/cjs files, but because the change is breaking, it will wait until the next major. Until then, the workaround adds an exports field and adds type-module only for the esm folder. |
The official documentation guide: Output webpack stats with webpack-stats-plugin
In the documentation the example given for importing the package is in CommonJs;
const filterWebpackStats = require('@bundle-stats/plugin-webpack-filter').default;
Importing the module using ESM syntax would then use the following;
import filterWebpackStats from '@bundle-stats/plugin-webpack-filter'
However, this then throws a run-time error from the following line in the documentation (error: 'not a function');
const filteredSource = filterWebpackStats(webpackStats);
The run-time error can be solved by using
filterWebpackStats.default(webpackStats);
;However, this throws up a type-error:
Property 'default' does not exist on type '(source: StatsCompilation, options?: BundleStatsOptions | undefined) => WebpackStatsFiltered'
I was able to solve this by adding a declaration to my .d.ts file;
Basically, I'm looking to understand what is going on here and whether this is an error in the type definitions for the library, or whether it is intentional - from my research it seems like there is a history involving CommonJS, ESM, and how libraries have been constructed along the timeline of developments.
The text was updated successfully, but these errors were encountered: