mirror of
https://github.com/davidkaya/aryx.git
synced 2026-07-29 07:58:47 +02:00
fix: resolve Prism CJS loading crash in Vite dev mode
Remove the prismSetup module that imported prismjs directly — it caused Vite to pre-bundle prismjs into a separate chunk from @lexical/code-prism, breaking the CJS require chain. Language components tried to call Prism.languages.extend() before the base grammars were available, crashing the app. Instead, add optimizeDeps.include for prismjs and @lexical/code-prism so Vite pre-bundles them together, preserving the correct CJS evaluation order within a single chunk. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -33,6 +33,12 @@ export default defineConfig({
|
|||||||
build: {
|
build: {
|
||||||
outDir: 'dist/renderer',
|
outDir: 'dist/renderer',
|
||||||
},
|
},
|
||||||
|
optimizeDeps: {
|
||||||
|
// @lexical/code-prism depends on prismjs + its language components via
|
||||||
|
// CJS require(). Vite must pre-bundle them together so that the Prism
|
||||||
|
// global is available when component IIFEs execute.
|
||||||
|
include: ['prismjs', '@lexical/code-prism'],
|
||||||
|
},
|
||||||
plugins: [react(), tailwindcss()],
|
plugins: [react(), tailwindcss()],
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
/**
|
|
||||||
* Ensures the PrismJS global is available before @lexical/code-prism
|
|
||||||
* captures its tokenizer reference.
|
|
||||||
*
|
|
||||||
* @lexical/code-prism reads `globalThis.Prism` at module-evaluation time.
|
|
||||||
* In Vite dev mode the esbuild CJS shim may not have set the global yet,
|
|
||||||
* so we force it here. This module must be imported before any module
|
|
||||||
* that transitively loads @lexical/code-prism.
|
|
||||||
*/
|
|
||||||
import Prism from 'prismjs';
|
|
||||||
|
|
||||||
if (typeof globalThis !== 'undefined' && !globalThis.Prism) {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
(globalThis as any).Prism = Prism;
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
import { StrictMode } from 'react';
|
import { StrictMode } from 'react';
|
||||||
import { createRoot } from 'react-dom/client';
|
import { createRoot } from 'react-dom/client';
|
||||||
|
|
||||||
import '@renderer/lib/prismSetup';
|
|
||||||
import App from '@renderer/App';
|
import App from '@renderer/App';
|
||||||
import '@renderer/styles.css';
|
import '@renderer/styles.css';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user