Skip to content

Commit 8e77cfa

Browse files
committed
fix(vite): Fix EPERM error
1 parent d1748c0 commit 8e77cfa

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import process from 'node:process'
2+
import { chmodSync } from 'node:fs'
23
import type { UnpluginFactory } from 'unplugin'
34
import { createUnplugin } from 'unplugin'
45
import type { ResolvedConfig, ViteDevServer } from 'vite'
@@ -37,12 +38,12 @@ function registerExit(clear: (() => Promise<any>) | (() => any)) {
3738

3839
process.once('SIGINT', async () => {
3940
await clear()
40-
process.emit('SIGINT')
41+
process.exit(0)
4142
})
4243

4344
process.once('SIGTERM', async () => {
4445
await clear()
45-
process.emit('SIGTERM')
46+
process.exit(0)
4647
})
4748
}
4849

@@ -87,6 +88,12 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
8788
const _printUrls = server.printUrls
8889
server.printUrls = () => {
8990
_printUrls()
91+
92+
// fix `Error: EPERM: operation not permitted`
93+
const pwd = process.cwd()
94+
const vireCacheDir = `${pwd}/node_modules/.vite`
95+
chmodSync(vireCacheDir, 0o777)
96+
9097
let source = `localhost:${config.server.port}`
9198
const url = server.resolvedUrls?.local[0]
9299
if (url) {

0 commit comments

Comments
 (0)