index.mjs messes up default import
thany opened this issue ยท 7 comments
Default export not found. This problem started existing since the index.mjs
was added. When I delete or rename this file from the installed package, it builds fine. When I put it back, I get these warnings again.
Maybe our webpack config is picking up index.mjs
in favour of index.js
, but it shouldn't, since I'm explicitly telling it to only find .js
and .jsx
files in the babel-loader config.
Last known working version is 1.1.2. I'll be downgrading for the time being, since downgrading feels like the most reliable thing to do until a proper fix becomes available.
Expected Behavior
Build OK, no warnings.
Actual Behavior
Warnings everywhere this package is being used:
export 'default' (imported as 'parse') was not found in 'html-react-parser'
Steps to Reproduce
Just import like this:
import parse from 'html-react-parser';
Workaround is to import like this:
import * as parse from 'html-react-parser';
Which works absolutely fine. But since the former notation is in the docs, I'm assuming that's how it's intended to be. Hence why the latter form is a workaround - not a solution.
Reproducible Demo
Sorry, it's a really complicated project, I'm not sure if I can do this. If it's really really really really neccesary, I can give it a go, but honestly, this problem is already costing me so much time ๐
Environment
- Version: 1.2.4
- Platform: Windows 10
- Browser: Firefox 89
Sorry to hear about the issue @thany.
As a workaround, can you configure your webpack config?
Thanks, I'll give it a go after Easter.
That did the trick! ๐
For future reference, I had to go for:
resolve: {
// ...
mainFields: ['main', 'module'],
}
Since in our case, it builds to a module for SSR purposes, instead of a regular thing that goes to the browser.
Now, I do still wonder. Is this a solution or merely a workaround? I'm not sure if this still requires a proper solution, or if the above is the actual proper solution.
So far, I haven't seen a lot issues regarding the index.mjs
change (except for when I actually did break something). I believe this is a workaround for those with more complex webpack configs.
Fair enough, then let's consider this a proper solution.
@thany would you like to document this in the README.md
? And are we good to close this issue?
That might be helpful, yes. Good to close ๐๐ป