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

12.1.0 no longer importable in node with ESM #1589

Closed
sventschui opened this issue Dec 6, 2022 · 3 comments
Closed

12.1.0 no longer importable in node with ESM #1589

sventschui opened this issue Dec 6, 2022 · 3 comments

Comments

@sventschui
Copy link

sventschui commented Dec 6, 2022

💥 Regression Report

The exports map added in 12.1.0 break import 'react-i18next' / import("react-i18next") statements in node.js (require('react-i18next') still working fine).

Last working version

Worked up to version: 12.0.0

Stopped working in version: 12.1.0

To Reproduce

Steps to reproduce the behavior:

  • Install react-18next@12.1.0
  • Run node --experimental-specifier-resolution=node --input-type module --eval 'import { I18nextProvider } from "react-i18next"'

Expected behavior

Should not crash. (Note a warning about experimental node flags will be printed)

Actual behaviour

Crashes with the following error:

node --experimental-specifier-resolution=node --input-type module --eval 'import { I18nextProvider } from "react-i18next"'
(node:89634) ExperimentalWarning: The Node.js specifier resolution flag is experimental. It could change or be removed at any time.
(Use `node --trace-warnings ...` to show where the warning was created)
******[eval1]:1
import { I18nextProvider } from "react-i18next"
         ^^^^^^^^^^^^^^^
SyntaxError: Named export 'I18nextProvider' not found. The requested module 'react-i18next' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'react-i18next';
const { I18nextProvider } = pkg;

Potential fixes

  • Use .mjs instead of .js extension to let node know the files are in ESM format (i.e. dist/es/index.mjs instead of dist/es/index.js)
  • Create a dist/package.json file with the contents { "type": "module" } to let node know the files are in ESM format.

Your Environment

  • runtime version: node 16, 18, 19
  • i18next version: n/a
  • os: Mac
@adrai adrai closed this as completed in 03640ed Dec 7, 2022
@adrai
Copy link
Member

adrai commented Dec 7, 2022

v12.1.1 should fix this

@sventschui
Copy link
Author

Thanks for this quick fix, really appreciated 🥇

@adrai
Copy link
Member

adrai commented Dec 7, 2022

If you like this module don’t forget to star this repo. Make a tweet, share the word or have a look at our https://locize.com to support the devs of this project.

There are many ways to help this project 🙏

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