-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Cannot import "exports": { "module": ... } without type=module configured packages, instead we could get an error: Cannot use import statement outside a module #9070
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
Comments
…ad we could get an error: Cannot use import statement outside a module Reproduction of remix-run#9070
Is there any update on this issue? I am experiencing it with
|
I am also experiencing the same issue |
I've been running into the same issue with several packages such as |
I encountered the same issue when using chartjs-react. Following the suggestions from the original poster and this comment, I tried the following two solutions, both of which resolved the issue:
|
Thanks ! It works for me. But i might be concerned. How changing the file name to .client.tsx exaclty solves the problem ? And how this change impact the application as whole ? |
This is still an issue at the time of posting this message, I'm using react-router 7.3. The solution that worked for me was adding the troublesome libraries to |
Thank you for opening this issue, and our apologies we haven't gotten around to it yet! With the release of React Router v7 we are sun-setting continued development/maintenance on Remix v2. If you have not already upgraded to React Router v7, we recommend you do so. We've tried to make the upgrade process as smooth as possible with our Future Flags. We are now in the process of cleaning up outdated issues and pull requests to improve the overall hygiene of our repositories. We plan to continue to address 2 types of issues in Remix v2:
If you believe this issue meets one of those criteria, please respond or create a new issue. For all other issues, ongoing maintenance will be happening in React Router v7, so:
If you have any questions you can always reach out on Discord. Thanks again for providing feedback and helping us make our framework even better! |
Uh oh!
There was an error while loading. Please reload this page.
Reproduction
Quick: Go to https://stackblitz.com/edit/remix-run-remix-cqepq2?file=app%2Froutes%2F_index.tsx
Or see #9071
'use-immer'
The package which causes this problem has these conditions:
type: module
in package.jsonexports: { ".": { import: "something" }}
in package.jsonThe package.json in [email protected], you can see like this:
And we can confirm this satisfies the condition.
Actually, if I add "type=module" to this, and restart remix run, it succeeds to import.
Extra contexts
related:
This could be the bug of vite. I can create issue instead on vite, but I'm not sure for now.
The most important part of this issue is I got small reproduction for these issues (currently discussions).
I'm also making PR for Option 1 after submitting this issue.Done.By the way, you may think, such packages should have
type: module
in their package.json. Actually, import from these packages from esm does not work, and multi-support is actually not possible by native level. Even if type=module is added, now, it cannot be require-able.Sadly, this is complicated situation. Node.js, TypeScript and Webpack treats exports as their own way. Webpack says as https://webpack.js.org/guides/package-exports/#support .
Thanks.
System Info
Used Package Manager
npm
Expected Behavior
Not get error and just can import it as ESM module as usual.
Actual Behavior
Got an error:
We have the workaround for this, just with importing by relative path:
The text was updated successfully, but these errors were encountered: