question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fatal Error [ERR_REQUIRE_ESM]: require() of ES Module vite-ssr\server\pageFiles.mjs not supported

See original GitHub issue

Description

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:closed
  • Created 9 months ago
  • Comments:22 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
brilloutcommented, Dec 26, 2022

Last time I tried TSX I had issues with it. I’ll give it another shot.

RE: deno, lovely, but I expect several unforseen edge cases like this one.

FYI https://twitter.com/biwanczuk/status/1607332213384974336.

0reactions
samuelstroscheincommented, Dec 26, 2022

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found