Skip to content

Commit

Permalink
"type": "module" 下, 不存在require, 导致报错误 (#96)
Browse files Browse the repository at this point in the history
"type": "module" 下, 不存在require, 导致报`require is not defined`错误

Co-authored-by: jinmao88 <[email protected]>
  • Loading branch information
lincenying and jinmao88 authored Jan 17, 2024
1 parent e9f479f commit c1e35e4
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/vite-plugin-mock/src/createMockServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,21 @@ function createWatch(opt: ViteMockOptions, config: ResolvedConfig) {
})
}


// clear cache
function cleanRequireCache(opt: ViteMockOptions) {
if (typeof require === 'undefined' || !require.cache) {
return
}
const { absConfigPath, absMockPath } = getPath(opt)
Object.keys(require.cache).forEach((file) => {
if (file === absConfigPath || file.indexOf(absMockPath) > -1) {
delete require.cache[file]
}
})
}


function parseJson(req: IncomingMessage): Promise<Recordable> {
return new Promise((resolve) => {
let body = ''
Expand Down

0 comments on commit c1e35e4

Please sign in to comment.