SSR Error: "require is not defined" with @lexical/react
as dependency in Astro
#10353
Labels
needs triage
Issue needs to be triaged
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
During SSR builds with Astro, I encounter a
"require is not defined"
error that traces back to@lexical/react/LexicalHistoryPlugin.js
. This issue arises after configuringnoExternal
in Astro's Vite configuration to ensure proper handling of CommonJS dependencies which@mdxeditor/editor
relies on, including@lexical/react
and others. The aim was to mitigate a separate issue where named exports from these CommonJS modules were not being recognized.Error Message:
Additional Context:
Initial Issue with Named Exports: The configuration adjustment was initially triggered by an error relating to named exports from CommonJS modules, specifically:
Configuration for
noExternal
: To address this, the following configurations were made inastro.config.mjs
, targeting a better integration of these CommonJS dependencies into the SSR build process:Compatibility Note: Interestingly,
@mdxeditor/editor
(along with its related dependencies) operates correctly in a simpler React + Vite environment, suggesting the issue might be specific to how Astro's SSR engine manages these CommonJS modules.What's the expected result?
The expected result is for Astro to successfully complete the SSR build without encountering module resolution errors, allowing
@mdxeditor/editor
and its dependencies to be integrated seamlessly in an Astro project.Link to Minimal Reproducible Example
Codesandbox Link
Participation
The text was updated successfully, but these errors were encountered: