Skip to content

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
Member

@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

@eoghanmurray
Copy link
Contributor

This may cause programs that import rrweb through CDN links to fail.

This is the case with jsdelivr I believe; e.g. the following fails as it's served as application/node:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/rrweb-player.umd.cjs"></script>

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

4 participants