From 12c2e74db733d521181df68b12881154c9323ef5 Mon Sep 17 00:00:00 2001 From: Steven DeMartini Date: Tue, 20 Aug 2024 17:24:34 -0700 Subject: [PATCH] Force node to use CJS to get around dependency import errors Both `@mui/icons-material` (https://github.com/mui/material-ui/issues/35233) and `lodash` (https://github.com/lodash/lodash/issues/5107) have problems being imported in a consuming package when using ESM. The workarounds attempted in https://github.com/sjdemartini/mui-tiptap/pull/258 almost seemed to work (didn't break a downstream bundled package using Vite), but still caused problems for the original example node application https://codesandbox.io/p/devbox/pensive-volhard-hyhtls, with errors like: ``` Error: Cannot find module '/path/to/mui-tiptap-in-node/node_modules/@mui/icons-material/esm/FormatColorFill ``` This approach is inspired by what tss-react does https://github.com/garronej/tss-react/blob/f5351e42e33f35f18415cfc1ffc6b08eb8ce4d25/package.json (e.g. see here https://github.com/garronej/tss-react/commit/46997026db70ec9bc326a1405d1ab7ea99a8d111 and https://github.com/garronej/tss-react/issues/164). --- example/pnpm-lock.yaml | 2 +- package.json | 21 +++++++++++---------- tsconfig.build.json | 5 ++++- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/example/pnpm-lock.yaml b/example/pnpm-lock.yaml index 9f734bd..6a6bd28 100644 --- a/example/pnpm-lock.yaml +++ b/example/pnpm-lock.yaml @@ -2559,7 +2559,7 @@ packages: resolution: {directory: .., type: directory} id: file:.. name: mui-tiptap - version: 1.9.1 + version: 1.9.5 engines: {pnpm: '>=8'} requiresBuild: true peerDependencies: diff --git a/package.json b/package.json index 5aa6f1d..c3165a8 100644 --- a/package.json +++ b/package.json @@ -22,25 +22,26 @@ "dist" ], "type": "commonjs", - "types": "./dist/index.d.ts", - "main": "dist/index.js", + "types": "./dist/cjs/index.d.ts", + "main": "dist/cjs/index.js", "module": "dist/esm/index.js", "exports": { ".": { - "types": "./dist/index.d.ts", - "require": "./dist/index.js", - "import": "./dist/esm/index.js" + "types": "./dist/cjs/index.d.ts", + "module": "./dist/esm/index.js", + "default": "./dist/cjs/index.js" }, "./icons": { - "types": "./dist/icons/index.d.ts", - "require": "./dist/icons/index.js", - "import": "./dist/esm/icons/index.js" - } + "types": "./dist/cjs/icons/index.d.ts", + "module": "./dist/esm/icons/index.js", + "default": "./dist/cjs/icons/index.js" + }, + "./package.json": "./package.json" }, "typesVersions": { "*": { "icons": [ - "./dist/icons/index.d.ts" + "./dist/cjs/icons/index.d.ts" ], "*": [ "*" diff --git a/tsconfig.build.json b/tsconfig.build.json index 78c4f09..67a2e24 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,5 +1,8 @@ { "extends": "./tsconfig.json", "include": ["./src"], - "exclude": ["./src/demo", "./src/**/__tests__"] + "exclude": ["./src/demo", "./src/**/__tests__"], + "compilerOptions": { + "outDir": "./dist/cjs" + } }