diff --git a/packages/docusaurus/src/server/index.ts b/packages/docusaurus/src/server/index.ts index 0afbea7315..62a1ee2e04 100644 --- a/packages/docusaurus/src/server/index.ts +++ b/packages/docusaurus/src/server/index.ts @@ -129,7 +129,8 @@ export async function load(siteDir: string): Promise { `export default [\n${clientModules // import() is async so we use require() because client modules can have // CSS and the order matters for loading CSS. - .map(module => ` require("${module}"),`) + // We need to JSON.stringify so that if its on windows, backslash are escaped. + .map(module => ` require(${JSON.stringify(module)}),`) .join('\n')}\n];\n`, ); @@ -152,7 +153,10 @@ ${Object.keys(registry) .sort() .map( key => - ` '${key}': [${registry[key].loader}, "${registry[key].modulePath}", require.resolveWeak("${registry[key].modulePath}")],`, + // We need to JSON.stringify so that if its on windows, backslash are escaped. + ` '${key}': [${registry[key].loader}, ${JSON.stringify( + registry[key].modulePath, + )}, require.resolveWeak(${JSON.stringify(registry[key].modulePath)})],`, ) .join('\n')}};\n`, );