From 781718c2e9e72c7b54fb839284eb7503b8753bd6 Mon Sep 17 00:00:00 2001 From: Titouan Mathis Date: Mon, 31 Jan 2022 10:50:43 +0100 Subject: [PATCH] fix: ERR_REQUIRE_ESM error when project type is set to module --- src/node/plugin.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/node/plugin.ts b/src/node/plugin.ts index fc6d8e6fd146..4f6037c082f2 100644 --- a/src/node/plugin.ts +++ b/src/node/plugin.ts @@ -1,4 +1,5 @@ import path from 'path' +import fs from 'fs-extra' import { defineConfig, mergeConfig, Plugin, ResolvedConfig } from 'vite' import { SiteConfig, resolveSiteData } from './config' import { @@ -276,6 +277,15 @@ export function createVitePressPlugin( // overwrite src so vue plugin can handle the HMR ctx.read = () => vueSrc } + }, + + writeBundle(_options) { + if (ssr && _options.dir && _options.format === 'cjs') { + fs.writeFileSync( + path.join(_options.dir, 'package.json'), + JSON.stringify({ type: 'commonjs' }) + ) + } } }