Skip to content

Commit

Permalink
fix: ERR_REQUIRE_ESM error when project type is set to module
Browse files Browse the repository at this point in the history
  • Loading branch information
titouanmathis committed Jan 31, 2022
1 parent 45b65ce commit b09500f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/node/plugin.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -11,8 +12,7 @@ import { OutputAsset, OutputChunk } from 'rollup'
import { staticDataPlugin } from './staticDataPlugin'

const hashRE = /\.(\w+)\.js$/
const staticInjectMarkerRE =
/\b(const _hoisted_\d+ = \/\*(?:#|@)__PURE__\*\/\s*createStaticVNode)\("(.*)", (\d+)\)/g
const staticInjectMarkerRE = /\b(const _hoisted_\d+ = \/\*(?:#|@)__PURE__\*\/\s*createStaticVNode)\("(.*)", (\d+)\)/g
const staticStripRE = /['"`]__VP_STATIC_START__[^]*?__VP_STATIC_END__['"`]/g
const staticRestoreRE = /__VP_STATIC_(START|END)__/g

Expand Down Expand Up @@ -276,6 +276,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' })
)
}
}
}

Expand Down

0 comments on commit b09500f

Please sign in to comment.