react-use icon indicating copy to clipboard operation
react-use copied to clipboard

build: support ES modules

Open oblador opened this issue 1 year ago • 5 comments

Description

This package can't be used in a node environment using ESM as it's neither declared as "type": "module" nor does it include .mjs extensions for the files in the module main field.

Since TSC is not able to produce proper ESM files with .mjs extensions I opted to use tsup to compile the ESM files, and I also had to add @swc/core to keep this backwards compatible with the es5 target. I don't think there's much point in supporting back to es5 for an ESM, but I'm keeping it for now to avoid making this a breaking change.

Fixes #2353

Type of change

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as before)

Checklist

  • [x] Read the Contributing Guide
  • [x] Perform a code self-review
  • [x] Comment the code, particularly in hard-to-understand areas
  • [x] Add documentation
  • [x] Add hook's story at Storybook
  • [x] Cover changes with tests
  • [x] Ensure the test suite passes (yarn test)
  • [x] Provide 100% tests coverage
  • [x] Make sure code lints (yarn lint). Fix it with yarn lint:fix in case of failure.
  • [x] Make sure types are fine (yarn lint:types).

oblador avatar Sep 27 '24 16:09 oblador

@joecritch Can you look at this? It's been problematic for years

bertho-zero avatar Feb 06 '25 17:02 bertho-zero

The same question, is there a plan to merge this PR?

Error in renderToPipeableStream: SyntaxError: [vite] Named export 'useThrottle' not found. The requested module 'react-use' 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-use';
const {useThrottle} = pkg;

rxliuli avatar May 25 '25 05:05 rxliuli

Any chance of getting this merged? I feel it's a simple change that would make a monumental difference

WaldoJeffers avatar Dec 04 '25 16:12 WaldoJeffers

How is this not yet supported? It really breaks SSRs frameworks

tomerzcod7 avatar Dec 13 '25 15:12 tomerzcod7

How is this not yet supported? It really breaks SSRs frameworks

The author seems to have abandoned maintaining this package, I'm considering whether to fork it. There hasn't been any meaningful commit throughout the entire 2025.

https://github.com/streamich/react-use/commits/master/

rxliuli avatar Dec 13 '25 15:12 rxliuli