javascriptvue.jsvitevitepress

Unknown Issue with Vitepress


After I use pnpm initialize my vitepress project with latest vitepress version, I use pnpm run docs:dev to try running it. And it appears such errors:

✘ [ERROR] "vitepress" resolved to an ESM file. ESM file cannot be loaded by `require`. See http://vitejs.dev/guide/troubleshooting.html#this-package-is-esm-only for more details. [plugin externalize-deps]

    node_modules/.pnpm/esbuild@0.18.20/node_modules/esbuild/lib/main.js:1373:27:
      1373 │         let result = await callback({
           ╵                            ^

    at file:///C:/Users/CoolPlayLin/Project/ChatGPT-Wiki/node_modules/.pnpm/vite@4.4.9/node_modules/vite/dist/node/chunks/dep-df561101.js:66190:35
    at requestCallbacks.on-resolve (C:\Users\CoolPlayLin\Project\ChatGPT-Wiki\node_modules\.pnpm\esbuild@0.18.20\node_modules\esbuild\lib\main.js:1373:28)
    at handleRequest (C:\Users\CoolPlayLin\Project\ChatGPT-Wiki\node_modules\.pnpm\esbuild@0.18.20\node_modules\esbuild\lib\main.js:729:19)
    at handleIncomingPacket (C:\Users\CoolPlayLin\Project\ChatGPT-Wiki\node_modules\.pnpm\esbuild@0.18.20\node_modules\esbuild\lib\main.js:755:7)
    at Socket.readFromStdout (C:\Users\CoolPlayLin\Project\ChatGPT-Wiki\node_modules\.pnpm\esbuild@0.18.20\node_modules\esbuild\lib\main.js:679:7)
    at Socket.emit (node:events:514:28)
    at addChunk (node:internal/streams/readable:343:12)
    at readableAddChunk (node:internal/streams/readable:316:9)
    at Readable.push (node:internal/streams/readable:253:10)
    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)

  This error came from the "onResolve" callback registered here:

    node_modules/.pnpm/esbuild@0.18.20/node_modules/esbuild/lib/main.js:1292:20:
      1292 │       let promise = setup({
           ╵                     ^

    at setup (file:///C:/Users/CoolPlayLin/Project/ChatGPT-Wiki/node_modules/.pnpm/vite@4.4.9/node_modules/vite/dist/node/chunks/dep-df561101.js:66158:27)
    at handlePlugins (C:\Users\CoolPlayLin\Project\ChatGPT-Wiki\node_modules\.pnpm\esbuild@0.18.20\node_modules\esbuild\lib\main.js:1292:21)
    at buildOrContextImpl (C:\Users\CoolPlayLin\Project\ChatGPT-Wiki\node_modules\.pnpm\esbuild@0.18.20\node_modules\esbuild\lib\main.js:978:5)
    at Object.buildOrContext (C:\Users\CoolPlayLin\Project\ChatGPT-Wiki\node_modules\.pnpm\esbuild@0.18.20\node_modules\esbuild\lib\main.js:786:5)
    at C:\Users\CoolPlayLin\Project\ChatGPT-Wiki\node_modules\.pnpm\esbuild@0.18.20\node_modules\esbuild\lib\main.js:2177:15
    at new Promise (<anonymous>)
    at Object.build (C:\Users\CoolPlayLin\Project\ChatGPT-Wiki\node_modules\.pnpm\esbuild@0.18.20\node_modules\esbuild\lib\main.js:2176:25)
    at build (C:\Users\CoolPlayLin\Project\ChatGPT-Wiki\node_modules\.pnpm\esbuild@0.18.20\node_modules\esbuild\lib\main.js:2025:51)
    at bundleConfigFile (file:///C:/Users/CoolPlayLin/Project/ChatGPT-Wiki/node_modules/.pnpm/vite@4.4.9/node_modules/vite/dist/node/chunks/dep-df561101.js:66109:26)

  The plugin "externalize-deps" was triggered by this import

    docs/.vitepress/config.js:1:382:
      1 │ ...olPlayLin/Project/ChatGPT-Wiki/docs/.vitepress/config.js";import { defineConfig } from 'vitepress' 
        ╵                                                                                           ~~~~~~~~~~~ 

failed to load config from C:\Users\CoolPlayLin\Project\ChatGPT-Wiki\docs\.vitepress\config.js
failed to start server. error:
Error: Build failed with 1 error:
node_modules/.pnpm/esbuild@0.18.20/node_modules/esbuild/lib/main.js:1373:27: ERROR: [plugin: externalize-deps] "vitepress" resolved to an ESM file. ESM file cannot be loaded by `require`. See http://vitejs.dev/guide/troubleshooting.html#this-package-is-esm-only for more details.
    at failureErrorWithLog (C:\Users\CoolPlayLin\Project\ChatGPT-Wiki\node_modules\.pnpm\esbuild@0.18.20\node_modules\esbuild\lib\main.js:1649:15)
    at C:\Users\CoolPlayLin\Project\ChatGPT-Wiki\node_modules\.pnpm\esbuild@0.18.20\node_modules\esbuild\lib\main.js:1058:25
    at runOnEndCallbacks (C:\Users\CoolPlayLin\Project\ChatGPT-Wiki\node_modules\.pnpm\esbuild@0.18.20\node_modules\esbuild\lib\main.js:1484:45)
    at buildResponseToResult (C:\Users\CoolPlayLin\Project\ChatGPT-Wiki\node_modules\.pnpm\esbuild@0.18.20\node_modules\esbuild\lib\main.js:1056:7)
    at C:\Users\CoolPlayLin\Project\ChatGPT-Wiki\node_modules\.pnpm\esbuild@0.18.20\node_modules\esbuild\lib\main.js:1085:16
    at responseCallbacks.<computed> (C:\Users\CoolPlayLin\Project\ChatGPT-Wiki\node_modules\.pnpm\esbuild@0.18.20\node_modules\esbuild\lib\main.js:703:9)
    at handleIncomingPacket (C:\Users\CoolPlayLin\Project\ChatGPT-Wiki\node_modules\.pnpm\esbuild@0.18.20\node_modules\esbuild\lib\main.js:762:9)
    at Socket.readFromStdout (C:\Users\CoolPlayLin\Project\ChatGPT-Wiki\node_modules\.pnpm\esbuild@0.18.20\node_modules\esbuild\lib\main.js:679:7)
    at Socket.emit (node:events:514:28)
    at addChunk (node:internal/streams/readable:343:12)
 ELIFECYCLE  Command failed with exit code 1.

What should I do to resolve it?

I try running it with pnpm run docs:dev. I expect it would be run successfully


Solution

  • package.json add "type": "module"