From fe69bd6456cead304bfc77cf72c9db0f8c030842 Mon Sep 17 00:00:00 2001 From: Yun Feng Date: Tue, 10 Jan 2023 17:20:03 +0800 Subject: [PATCH] fix: module error (#1087) * fix: module error 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. * update jest config files --- packages/rrdom-nodejs/package.json | 2 +- packages/rrdom/jest.config.js | 2 +- packages/rrdom/package.json | 3 ++- packages/rrweb-player/package.json | 3 ++- packages/rrweb-snapshot/jest.config.js | 2 +- packages/rrweb-snapshot/package.json | 3 ++- packages/rrweb/package.json | 2 +- packages/rrweb/rollup.config.js | 2 +- 8 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/rrdom-nodejs/package.json b/packages/rrdom-nodejs/package.json index f1be1665aa..8e947a6ce0 100644 --- a/packages/rrdom-nodejs/package.json +++ b/packages/rrdom-nodejs/package.json @@ -15,7 +15,7 @@ "rrdom-nodejs" ], "license": "MIT", - "main": "lib/rrdom-nodejs.js", + "main": "lib/rrdom-nodejs.cjs", "module": "es/rrdom-nodejs.js", "typings": "es", "files": [ diff --git a/packages/rrdom/jest.config.js b/packages/rrdom/jest.config.js index e86e13bab9..e5841e937d 100644 --- a/packages/rrdom/jest.config.js +++ b/packages/rrdom/jest.config.js @@ -1,5 +1,5 @@ /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ -module.exports = { +export default { preset: 'ts-jest', testEnvironment: 'node', }; diff --git a/packages/rrdom/package.json b/packages/rrdom/package.json index 8048c9e072..b9e125c10f 100644 --- a/packages/rrdom/package.json +++ b/packages/rrdom/package.json @@ -3,7 +3,7 @@ "version": "0.1.7", "homepage": "https://github.com/rrweb-io/rrweb/tree/main/packages/rrdom#readme", "license": "MIT", - "main": "lib/rrdom.js", + "main": "lib/rrdom.cjs", "module": "es/rrdom.js", "typings": "es", "unpkg": "dist/rrdom.js", @@ -13,6 +13,7 @@ "es", "typings" ], + "type": "module", "repository": { "type": "git", "url": "git+https://github.com/rrweb-io/rrweb.git" diff --git a/packages/rrweb-player/package.json b/packages/rrweb-player/package.json index 224dbdd1d9..93368119d2 100644 --- a/packages/rrweb-player/package.json +++ b/packages/rrweb-player/package.json @@ -37,7 +37,7 @@ "lint": "yarn eslint src/**/*.ts" }, "description": "rrweb's replayer UI", - "main": "lib/index.js", + "main": "lib/index.cjs", "module": "dist/index.mjs", "unpkg": "dist/index.js", "files": [ @@ -46,6 +46,7 @@ "typings" ], "typings": "typings/index.d.ts", + "type": "module", "repository": { "type": "git", "url": "git+https://github.com/rrweb-io/rrweb.git" diff --git a/packages/rrweb-snapshot/jest.config.js b/packages/rrweb-snapshot/jest.config.js index 46cb05c37d..e6cdf180ee 100644 --- a/packages/rrweb-snapshot/jest.config.js +++ b/packages/rrweb-snapshot/jest.config.js @@ -1,5 +1,5 @@ /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ -module.exports = { +export default { preset: 'ts-jest', testEnvironment: 'node', testMatch: ['**/**.test.ts'], diff --git a/packages/rrweb-snapshot/package.json b/packages/rrweb-snapshot/package.json index 44b4d3e544..898209c5f5 100644 --- a/packages/rrweb-snapshot/package.json +++ b/packages/rrweb-snapshot/package.json @@ -14,6 +14,7 @@ "prepublish": "npm run typings && npm run bundle", "lint": "yarn eslint src" }, + "type": "module", "repository": { "type": "git", "url": "git+https://github.com/rrweb-io/rrweb.git" @@ -23,7 +24,7 @@ "snapshot", "DOM" ], - "main": "lib/rrweb-snapshot.js", + "main": "lib/rrweb-snapshot.cjs", "module": "es/rrweb-snapshot.js", "unpkg": "dist/rrweb-snapshot.js", "typings": "typings/index.d.ts", diff --git a/packages/rrweb/package.json b/packages/rrweb/package.json index 7295020de2..85117bdb56 100644 --- a/packages/rrweb/package.json +++ b/packages/rrweb/package.json @@ -27,7 +27,7 @@ "keywords": [ "rrweb" ], - "main": "lib/rrweb-all.js", + "main": "lib/rrweb-all.cjs", "module": "es/rrweb/packages/rrweb/src/entries/all.js", "unpkg": "dist/rrweb.js", "sideEffects": false, diff --git a/packages/rrweb/rollup.config.js b/packages/rrweb/rollup.config.js index 79f17e03f0..1875ea2064 100644 --- a/packages/rrweb/rollup.config.js +++ b/packages/rrweb/rollup.config.js @@ -186,7 +186,7 @@ for (const c of baseConfigs) { output: [ { format: 'cjs', - file: c.pathFn('lib/rrweb.js'), + file: c.pathFn('lib/rrweb.cjs'), }, ], });