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

fix: Make package importable for type="module" projects #586

Merged
merged 1 commit into from
Mar 16, 2023

Conversation

susnux
Copy link
Contributor

@susnux susnux commented Mar 5, 2023

Explicitly set the type of the dist files by changing the file extension to mjs or cjs respectively.

Without this fix, you get following error when importing from this package:

SyntaxError: Named export 'emit' not found. The requested module '@nextcloud/event-bus' 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 '@nextcloud/event-bus';
const { subscribe: r, emit: a, unsubscribe: c } = pkg;

This happens because the type is not set, so node assumes commonjs and will interpret every .js file as commonjs file regardless of the exports section.

Explicitly set the type of the dist files by changing the file
extension to `mjs` or `cjs` respectively.

Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
@susnux susnux force-pushed the fix/esm-exports branch from 2c7db8a to 1df0b73 Compare March 8, 2023 01:22
Copy link
Contributor

@skjnldsv skjnldsv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

@skjnldsv skjnldsv merged commit eaf9ea3 into master Mar 16, 2023
@delete-merged-branch delete-merged-branch bot deleted the fix/esm-exports branch March 16, 2023 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants