Using CRACO on a CRA 4.x React application, I need to configure @mdx-js/loader to use rehype plugins, and rehype-slug in particular. Now, rehype-slug's documentation says that I need to "import" this module.
If this isn't the proper place to ask for help, then please advice me where to ask instead.
As require.resolve("rehype-slug") fails with Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: ... I tried to switch to a craco.config.ts and import rehype-slug. This is my craco.config.ts:
This also fails in line 2, where the import statement is:
UnhandledPromiseRejectionWarning: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: lxkns/web/lxkns/node_modules/rehype-slug/index.js
require() of ES modules is not supported.
require() of lxkns/web/lxkns/node_modules/rehype-slug/index.js from lxkns/web/lxkns/craco.config.ts is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from lxkns/web/lxkns/node_modules/rehype-slug/package.json.
at new NodeError (internal/errors.js:322:7)
[...]
at Object.<anonymous> (/home/harald/github/lxkns/web/lxkns/craco.config.ts:2:1)
What stupid mistake am I doing here?
package.json has notype property setting.
tsconfig.json if that might give any clue as to what my error is:
@thediveo would it be possible to create a demo repo where this issue is reproduced (or perhaps share your package.json so I can try recreating the issue)?
Using CRACO on a CRA 4.x React application, I need to configure
@mdx-js/loader
to use rehype plugins, andrehype-slug
in particular. Now, rehype-slug's documentation says that I need to "import" this module.If this isn't the proper place to ask for help, then please advice me where to ask instead.
As
require.resolve("rehype-slug")
fails withError [ERR_REQUIRE_ESM]: Must use import to load ES Module: ...
I tried to switch to acraco.config.ts
and import rehype-slug. This is mycraco.config.ts
:This also fails in line 2, where the
import
statement is:What stupid mistake am I doing here?
package.json
has notype
property setting.tsconfig.json
if that might give any clue as to what my error is: