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

Support .cjs file #27

Closed
wants to merge 1 commit into from
Closed

Conversation

ergofriend
Copy link

Summary

  • Create React App's jest (react-scipts) can not import esm(.mjs) package.
  • For pass the test with react-merge-refs, it has to export .cjs file.
  • Probably, the module bundler does not affect the "module": "./dist/index.mjs", (ESM) loading priority over "main": "./dist/index.cjs".

Test plan

No diff in src.

@gregberge gregberge closed this in 8189083 Jun 27, 2022
@gregberge
Copy link
Owner

Hello @ergofriend, I don't want to expose cjs at all (size of package, dual package hazards..). I found a way to make it work with Jest. Don't know if it works with create-react-app without any config, but it could work. I use Jest on my side and I just had to make it parsed by Babel.

@cascornelissen
Copy link

cascornelissen commented Jun 27, 2022

@gregberge, do you have an example of how you use it with Jest? We're running into similar issues here as well and we're interested in a solution ❤️


For future reference, we ended up adding the following to our shared Jest configuration, along with adding mjs to moduleFileExtensions.

transform: {
    '^.+\\.mjs$': [require.resolve('babel-jest'), {
        presets: [require.resolve('@babel/preset-env')]
    }],
    // ...
}

@gregberge
Copy link
Owner

Yeah that's the best thing to do. Until Jest supports ESM completely. That's how I handle it too.

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

Successfully merging this pull request may close these issues.

3 participants