Skip to content

Conversation

@gaoachao
Copy link

Description

🐛 The Issue

The current ESM build outputs imports without file extensions (e.g., import ... from './useToggle').

This causes runtime errors in native Node.js environments (like Vitest or SSR), as the Node.js ESM Resolution Algorithm strictly requires explicit file extensions for relative imports.

💥 Error Log

FAIL  src/__tests__/index.test.tsx [ src/__tests__/index.test.tsx ]
Error: Cannot find module '/xxx/node_modules/react-use/esm/useToggle' imported from '/xxx/node_modules/react-use/esm/useBoolean.js'

🛠 The Fix

This PR ensures that all relative imports in the ESM output include the required .js extension to comply with the spec and fix the resolution error.

Type of change

  • 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

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

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.

1 participant