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

Wrong file extension for esm #2614

Open
ardjuh opened this issue Dec 19, 2024 · 0 comments
Open

Wrong file extension for esm #2614

ardjuh opened this issue Dec 19, 2024 · 0 comments

Comments

@ardjuh
Copy link

ardjuh commented Dec 19, 2024

What is the current behavior?
Vitest gives the following error when using a custom ui library with react-use:

SyntaxError: Cannot use import statement outside a module
Module .../node_modules/ui-lib/.../node_modules/react-use/esm/useInterval.js:1 seems to be an ES Module but shipped in a CommonJS package. You might want to create an issue to the package "react-use" asking them to ship the file in .mjs extension or add "type": "module" in their package.json.

As a temporary workaround you can try to inline the package by updating your config:

// vitest.config.js
export default {
  test: {
    server: {
      deps: {
        inline: [
          "react-use"
        ]
      }
    }
  }
}

This temporary workaround also doesn't fix the error.

Steps to reproduce it and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have extra dependencies other than react-use. Paste the link to your JSFiddle or CodeSandbox example below:
A ui library with

What is the expected behavior?
That the files in the esm folder have a .mjs extension and/or that the esm folder is marked is a module in the package.json

A little about versions:

  • OS: Not relevant
  • Browser (vendor and version): Not relevant
  • React: 18.2.0
  • react-use: 17.5.0
  • Did this worked in the previous package version?: No
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

1 participant