ricokahler / next-plugin-preval

Pre-evaluate async functions during builds and import them like JSON
MIT License
257 stars 13 forks source link

Import of the remark-gfm, rehype-slug and next-mdx-remote/serialize produce an error #94

Open mavr1k opened 2 years ago

mavr1k commented 2 years ago

I'm working on processing MD and MDX content using remark-gfm, rehype-slug and next-mdx-remote/serialize but I'm receiving an error shown below. Any variation of import (import from, dynamic import and require) doesn't change the behavior.

[next-plugin-preval] Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/user/projects/project/node_modules/remark-gfm/index.js from /Users/user/projects/project/src/preval/partials.preval.ts not supported.
Instead change the require of index.js in /Users/user/projects/project/src/preval/partials.preval.ts to a dynamic import() which is available in all CommonJS modules.
    at Object.newLoader [as .js] (/Users/user/projects/project/node_modules/pirates/lib/index.js:141:7)
    at /Users/user/projects/project/src/preval/partials.preval.ts:2:75
    at async serializeContentTest (/Users/user/projects/project/src/preval/partials.preval.ts:2:18)
    at async Promise.all (index 0)
    at async getPartials (/Users/user/projects/project/src/preval/partials.preval.ts:4:461)
    at async getPartialsConfigs (/Users/user/projects/project/src/preval/partials.preval.ts:5:240)
    at async /Users/user/projects/project/node_modules/next-plugin-preval/dist/loader.js:106:14
    at async _prevalLoader (/Users/user/projects/project/node_modules/next-plugin-preval/dist/loader.js:98:16)
error - ./src/preval/partials.preval.ts
Error: Failed to pre-evaluate "/Users/user/projects/project/src/preval/partials.preval.ts". Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/user/projects/project/node_modules/remark-gfm/index.js from /Users/user/projects/project/src/preval/partials.preval.ts not supported.
Instead change the require of index.js in /Users/user/projects/project/src/preval/partials.preval.ts to a dynamic import() which is available in all CommonJS modules. See above for full stack trace.
1OGAG commented 2 years ago

I have the same issue when using next-mdx-remote and serialize.

"next": "12.1.4", "next-mdx-remote": "^4.0.2", "next-plugin-preval": "^1.2.4", "react": "^17.0.2", "react-dom": "^17.0.2"

1OGAG commented 2 years ago

@mavr1k Did you get it to work? I am having the same problem.

getellez commented 7 months ago

same problem here