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: module error #1087

Merged
merged 2 commits into from
Jan 10, 2023
Merged

fix: module error #1087

merged 2 commits into from
Jan 10, 2023

Conversation

YunFeng0817
Copy link
Member

Fix #1056

Reason

In #976, a property type: "module" was added to the package.json. When it is set to "module", the type field allows a package to specify all .js files within are ES modules. If the "type" field is omitted or set to "commonjs", all .js files are treated as CommonJS. So all scripts under rrweb/lib/** are treated as esm format by JS bundlers unexpectedly.

Fix

Change all suffixes of bundled scripts with commonjs module from 'js' to cjs.

⚠️Breaking Change⚠️:

The file suffix of all scripts under rrweb/lib/* is changed from js to cjs. This may cause programs that import rrweb through CDN links to fail.

refactor all suffix of bundled scripts with commonjs module from 'js' to cjs

error:
ReferenceError: exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '.../rrweb/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
Copy link
Contributor

@Juice10 Juice10 left a comment

Choose a reason for hiding this comment

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

This is the way forward IMO, and 2.0 is the right moment to do it. I believe I did something similar in the vite.js branch, but that one isn’t finished yet so I’m happy we could get this in sooner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: ReferenceError: exports is not defined in ES module scope
2 participants