Skip to content

Commit

Permalink
Force node to use CJS to get around dependency import errors
Browse files Browse the repository at this point in the history
Both `@mui/icons-material`
(mui/material-ui#35233) and `lodash`
(lodash/lodash#5107) have problems being
imported in a consuming package when using ESM. The workarounds
attempted in #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
garronej/tss-react@4699702
and garronej/tss-react#164).
  • Loading branch information
sjdemartini committed Aug 21, 2024
1 parent 6ad0cfd commit 12c2e74
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion example/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
"*": [
"*"
Expand Down
5 changes: 4 additions & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"extends": "./tsconfig.json",
"include": ["./src"],
"exclude": ["./src/demo", "./src/**/__tests__"]
"exclude": ["./src/demo", "./src/**/__tests__"],
"compilerOptions": {
"outDir": "./dist/cjs"
}
}

0 comments on commit 12c2e74

Please sign in to comment.