Fatal Error [ERR_REQUIRE_ESM]: require() of ES Module vite-ssr\server\pageFiles.mjs not supported
See original GitHub issueDescription
This error occurs when routing to a page that I have not explicitly pre-rendered. (e.g. localhost/notAPage) It only occurs when serving the production build (SSG or SSR).
At some point between 0.4.54 and 0.4.60, this changed from merely printing to the console to causing my express server (basically a copy of the react boilerplace) to crash completely.
In 0.4.54:
Error [ERR_REQUIRE_ESM]: require() of ES Module [workspaceRoot]\dist\apps\hilton\vite-ssr\server\pageFiles.mjs not supported.
Instead change the require of [workspaceRoot]\dist\apps\hilton\vite-ssr\server\pageFiles.mjs to a dynamic import() which is available in all CommonJS modules.
at [workspaceRoot]\dist\apps\hilton\vite-ssr\server\importBuild.cjs:28:68
at async Promise.all (index 0)
at async loadBuild ([workspaceRoot]\node_modules\.pnpm\vite-plugin-ssr@0.4.54_33oe7thcih3clfsuwaxtnji33q\node_modules\vite-plugin-ssr\dist\cjs\node\plugin\plugins\importBuild\loadBuild.js:19:57)
at async getGlobalContext ([workspaceRoot]\node_modules\.pnpm\vite-plugin-ssr@0.4.54_33oe7thcih3clfsuwaxtnji33q\node_modules\vite-plugin-ssr\dist\cjs\node\globalContext.js:28:30)
at async initializePageContext ([workspaceRoot]\node_modules\.pnpm\vite-plugin-ssr@0.4.54_33oe7thcih3clfsuwaxtnji33q\node_modules\vite-plugin-ssr\dist\cjs\node\renderPage.js:128:27)
at async renderPage_ ([workspaceRoot]\node_modules\.pnpm\vite-plugin-ssr@0.4.54_33oe7thcih3clfsuwaxtnji33q\node_modules\vite-plugin-ssr\dist\cjs\node\renderPage.js:31:41)
at async renderPage ([workspaceRoot]\node_modules\.pnpm\vite-plugin-ssr@0.4.54_33oe7thcih3clfsuwaxtnji33q\node_modules\vite-plugin-ssr\dist\cjs\node\renderPage.js:158:16)
In 0.4.60:
[workspaceRoot]\node_modules\.pnpm\vite-plugin-ssr@0.4.60_33oe7thcih3clfsuwaxtnji33q\node_modules\vite-plugin-ssr\dist\cjs\node\plugin\plugins\importBuild\loadBuild.js:19
const [pageFiles, clientManifest, pluginManifest] = await Promise.all([
^
Error [ERR_REQUIRE_ESM]: require() of ES Module [workspaceRoot]\dist\apps\hilton\vite-ssr\server\pageFiles.mjs not supported.
Instead change the require of [workspaceRoot]\dist\apps\hilton\vite-ssr\server\pageFiles.mjs to a dynamic import() which is available in all CommonJS modules.
at [workspaceRoot]\dist\apps\hilton\vite-ssr\server\importBuild.cjs:28:68
at async Promise.all (index 0)
at async loadBuild ([workspaceRoot]\node_modules\.pnpm\vite-plugin-ssr@0.4.60_33oe7thcih3clfsuwaxtnji33q\node_modules\vite-plugin-ssr\dist\cjs\node\plugin\plugins\importBuild\loadBuild.js:19:57)
at async initGlobalContext ([workspaceRoot]\node_modules\.pnpm\vite-plugin-ssr@0.4.60_33oe7thcih3clfsuwaxtnji33q\node_modules\vite-plugin-ssr\dist\cjs\node\globalContext.js:32:30)
at async renderPage ([workspaceRoot]\node_modules\.pnpm\vite-plugin-ssr@0.4.60_33oe7thcih3clfsuwaxtnji33q\node_modules\vite-plugin-ssr\dist\cjs\node\renderPage.js:17:5) {
code: 'ERR_REQUIRE_ESM'
}
Error Message + Error Stack
No response
Issue Analytics
- State:
- Created 9 months ago
- Comments:22 (17 by maintainers)
Top Results From Across the Web
Error [ERR_REQUIRE_ESM]: require() of ES Module not ...
The node-fetch latest version doesn't use the require() syntax to import the package. You need to go to your package.json and type
Read more >Error [ERR_REQUIRE_ESM]: require() of ES Module not ...
js to a dynamic import() which is available in all CommonJS modules" occurs because a package you are importing has been converted to...
Read more >Must use import to load ES Module / require() of ES ... - GitHub
I have suddenly started getting the following error: $ npm test ... (node:7983) Warning: require() of ES modules is not supported.
Read more >require() of es modules is not supported - You.com - You.com
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: <project>\code\node_modules\split-on-first\index.js require() of ES modules is not supported.
Read more >Error [ERR_REQUIRE_ESM]: require() of ES Module - Support
Error [ERR_REQUIRE_ESM]: require() of ES Module when trying to compile a typescript service implementing the netlify api module. Version 11.0.1.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Last time I tried TSX I had issues with it. I’ll give it another shot.
FYI https://twitter.com/biwanczuk/status/1607332213384974336.
@brillout TSX works flawlessly. See TSX in action on the project I am working on https://gitpod.io/#https://github.com/inlang/inlang.
RE: deno, lovely, but I expect several unforseen edge cases like this one.