-
-
Notifications
You must be signed in to change notification settings - Fork 255
Module resolution issue with "module" property #369
Comments
hmm this is actually webpack's default behavior, https://webpack.js.org/configuration/resolve/#resolve-mainfields |
seems related to webpack/webpack#4742 |
Oof, apparently I need to work on my search skills. I found a reference to the mainFields setting, but didn’t think to look up the default value. I should be able override that setting in my poi config, right? If so, pointers appreciated, and go ahead and close this issue. |
You can directly mutate the webpack config https://poi.js.org/#/home?id=webpack |
but I think it should also be solved by webpack itself 🧐 |
I think I agree with the comment that you shouldn’t be exporting different things from the cjs and es modules. My problem is upstream, and I plan to open an issue there, but it comes down to the cjs module exporting a function and the esm exporting an object. We’ll see how that Webpack issue shakes out, but that’s the spec, after all. Thanks for input, and for creating this super useful tool. |
This issue has been marked as Stale, it will be closed in a week if there's no furthur activity. |
Do you want to request a feature or report a bug?
Report a bug
What is the current behavior?
Module resolution is wrong, it seems to be using the "module" property from child modules' package.json files.
If the current behavior is a bug, please provide the steps to reproduce.
I see this when attempting to use the
matchit
package, whichrequire
s a couple modules that ship with both"main"
and"module"
properties in their package.json files.1 -
npm install --dev poi; npm install matchit
2 - Add the example code from the readme to index.js
3 -
npx poi
4 - Open in browser, and check the console
You'll see an error "Uncaught TypeError: filter is not a function" coming from the index.js file in
matchit
. Since it's falling back to the module file, it's using es6 export, but the code is expecting the nodemodule.exports
version. You can also see this in the path in the build:./node_modules/@arr/filter/module.js
, which should be./node_modules/@arr/filter/index.js
What is the expected behavior?
Module resolution should be using
./node_modules/@arr/filter/index.js
, which is set in the"main"
property in the child module's package.json file.This code works as expected when run with node, ala
node index.js
.If you modify the
package.json
file innode_modules/@arr/filter/package.json
, removing the"module"
property, the code functions as expected.I can't figure out what's causing it, so this could be a Webpack problem too. As far as I can find, Webpack doesn't automatically resolve using the
"module"
property, so I thought I'd start here. Maybe there's something I can configure or disable that would solve the resolution issue?Please mention other relevant information such as the browser version, Node.js version, Poi version and Operating System.
poi
v9.6.13matchit
v1.0.1@arr/filter
v1.0.0The text was updated successfully, but these errors were encountered: