-
Notifications
You must be signed in to change notification settings - Fork 27
Closed
Description
Describe the bug
The @restart/ui
package provides ESM and CommonJS builds. However, the ESM build is not really compliant with Nodejs ESM module resolution.
To Reproduce
- Start a new Nodejs package with
type: "module"
- Add
@restart/ui
as a dependency - Add
index.js
file containing the following:import { useRootClose } from '@restart/ui'; console.log(useRootClose);
- Run the file with
node index.js
Reproducible Example
https://github.com/e1himself/restart-ui-esm-incompatibility-demo
The test run:
https://github.com/e1himself/restart-ui-esm-incompatibility-demo/actions/runs/4915733576/jobs/8778577614
Expected behavior
The ESM module import successfully resolves.
Actual behavior
import { useRootClose } from '@restart/ui';
^^^^^^^^^^^^
SyntaxError: Named export 'useRootClose' not found. The requested module '@restart/ui' 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 '@restart/ui';
const { useRootClose } = pkg;
at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:189:5)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
at async loadESM (node:internal/process/esm_loader:91:5)
at async handleMainPromise (node:internal/modules/run_main:65:12)
Environment (please complete the following information)
- Operating System: Fedora Linux
- Node v16.20.0
- NPM 8.19.4
Metadata
Metadata
Assignees
Labels
No labels