Skip to content
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

index.mjs messes up default import #238

Closed
thany opened this issue Apr 2, 2021 · 7 comments
Closed

index.mjs messes up default import #238

thany opened this issue Apr 2, 2021 · 7 comments

Comments

@thany
Copy link

thany commented Apr 2, 2021

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
@remarkablemark
Copy link
Owner

Sorry to hear about the issue @thany.

As a workaround, can you configure your webpack config?

@thany
Copy link
Author

thany commented Apr 4, 2021

Thanks, I'll give it a go after Easter.

@thany
Copy link
Author

thany commented Apr 6, 2021

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.

@remarkablemark
Copy link
Owner

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.

@thany
Copy link
Author

thany commented Apr 15, 2021

Fair enough, then let's consider this a proper solution.

@remarkablemark
Copy link
Owner

@thany would you like to document this in the README.md? And are we good to close this issue?

@thany
Copy link
Author

thany commented Apr 20, 2021

That might be helpful, yes. Good to close 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants