Dschungelabenteuer / vite-plugin-entry-shaking

Mimic tree-shaking behaviour when importing code from an entry file in development mode.
MIT License
124 stars 8 forks source link

[Bug]: Stackblitz example is failing #46

Closed oriooctopus closed 6 months ago

oriooctopus commented 6 months ago

What does the bug relate to?

Describe the bug

After opening the stackblitz link in the readme a sort of code sandbox is created and some initial commands are run. Those commands partially fail. See below:

~/Dschungelabenteuer/vite-plugin-entry-shaking
❯ pnpm install
 WARN  Unsupported engine: wanted: {"node":">=20.1.0"} (current: {"node":"v18.18.0","pnpm":"8.15.6"})
Scope: all 10 workspace projects
 WARN  There are cyclic workspace dependencies: /home/Dschungelabenteuer/vite-plugin-entry-shaking/packages/core, /home/Dschungelabenteuer/vite-plugin-entry-shaking/packages/debugger
preResolution: Hydrating content-addressable store.
Content-addressable store is at: ~/.local/share/pnpm/store/v3
Progress: total 1434, downloaded 1434, done

Lockfile is up to date, resolution step is skipped
Packages: +1411
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Progress: resolved 1411, reused 285, downloaded 0, added 28Progress: resolved 1411, reused 432, downloaded 0, added 43Progress: resolved 1411, reused 560, downloaded 0, added 56Progress: resolved 1411, reused 776, downloaded 0, added 77Progress: resolved 1411, reused 847, downloaded 0, added 84Progress: resolved 1411, reused 1074, downloaded 0, added 1Progress: resolved 1411, reused 1195, downloaded 0, added 1Progress: resolved 1411, reused 1409, downloaded 0, added 1Progress: resolved 1411, reused 1409, downloaded 0, added 1411, done

devDependencies:
+ @changesets/changelog-github 0.5.0
+ @changesets/cli 2.27.1
+ @types/prompts 2.4.9
+ @yungezeit/eslint-config-base 0.0.14
+ eslint 8.57.0
+ eslint-config-prettier 9.1.0
+ ora 8.0.1
+ prettier 3.2.5
+ prompts 2.4.2

. postinstall$ pnpm build
│  WARN  Unsupported engine: wanted: {"node":">=20.1.0"}…
│ > vite-plugin-entry-shaking-root@0.0.0 build /home/Dsc…
│ > pnpm --filter "./packages/**" build
│ .                                        |  WARN  Unsu…
│ Scope: 2 of 10 workspace projects
│ packages/core build$ pnpm unbuild
│ packages/debugger build$ vite build src/client && unbu…
│ packages/debugger build: ✘ [ERROR] Failed to resolve e…
│ packages/debugger build:     ../../node_modules/.pnpm/…
│ packages/debugger build:       48301 │         }
│ packages/debugger build:             ╵          ^
│ packages/debugger build:     at packageEntryFailure (/…
│ packages/debugger build:     at resolvePackageEntry (/…
│ packages/debugger build:     at tryNodeResolve (/home/…
│ packages/debugger build:     at resolveByViteResolver …
│ packages/debugger build:     at eval (/home/Dschungela…
│ packages/debugger build:     at requestCallbacks.on-re…
│ packages/debugger build:     at handleRequest (/home/D…
│ packages/debugger build:     at handleIncomingPacket (…
│ packages/debugger build:     at Socket.readFromStdout …
│ packages/debugger build:     at EventEmitter.emit (nod…
│ packages/debugger build:   This error came from the "o…
│ packages/debugger build:     ../../node_modules/.pnpm/…
│ packages/debugger build:       68486 │                …
│ packages/debugger build:             ╵                …
│ packages/debugger build:     at setup (/home/Dschungel…
│ packages/debugger build:     at handlePlugins (/home/D…
│ packages/debugger build:     at buildOrContextImpl (/h…
│ packages/debugger build:     at Object.buildOrContext …
│ packages/debugger build:     at eval (/home/Dschungela…
│ packages/debugger build:     at Object.build (/home/Ds…
│ packages/debugger build:     at Module.build (/home/Ds…
│ packages/debugger build:     at bundleConfigFile (/hom…
│ packages/debugger build:   The plugin "externalize-dep…
│ packages/debugger build:     mocks/diagnostics.ts:3:32:
│ packages/debugger build:       3 │ import { Diagnostic…
│ packages/debugger build:         ╵                    …
│ packages/debugger build: failed to load config from /h…
│ packages/debugger build: error during build:
│ packages/debugger build: Error: Build failed with 1 er…
│ packages/debugger build: ../../node_modules/.pnpm/vite…
│ packages/debugger build:     at failureErrorWithLog (/…
│ packages/debugger build:     at eval (/home/Dschungela…
│ packages/debugger build:     at runOnEndCallbacks (/ho…
│ packages/debugger build:     at buildResponseToResult …
│ packages/debugger build:     at eval (/home/Dschungela…
│ packages/debugger build:     at responseCallbacks.<com…
│ packages/debugger build:     at handleIncomingPacket (…
│ packages/debugger build:     at Socket.readFromStdout …
│ packages/debugger build:     at EventEmitter.emit (nod…
│ packages/debugger build:     at addChunk (node:interna…
│ packages/debugger build: Failed
│ /home/Dschungelabenteuer/vite-plugin-entry-shaking/pac…
│  ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL  vite-plugin-entry-…
│ Exit status 1
│  ELIFECYCLE  Command failed with exit code 1.
└─ Failed in 3.6s at /home/Dschungelabenteuer/vite-plugin-entry-shaking
 ELIFECYCLE  Command failed with exit code 1.

then if I generate an example and run dev I get

~/Dschungelabenteuer/vite-plugin-entry-shaking/examples/ballsack main
❯ pnpm run dev

> vite-plugin-entry-shaking-example-ballsack@0.0.0 dev /home/Dschungelabenteuer/vite-plugin-entry-shaking/examples/ballsack
> vite

✘ [ERROR] Failed to resolve entry for package "vite-plugin-entry-shaking". The package may have incorrect main/module/exports specified in its package.json. [plugin externalize-deps]

    ../../node_modules/.pnpm/vite@5.2.7_sass@1.72.0/node_modules/vite/dist/node/chunks/dep-C-KAszbv.js:48301:9:
      48301 │         }
            ╵          ^

    at packageEntryFailure (/home/Dschungelabenteuer/vite-plugin-entry-shaking/node_modules/.pnpm/vite@5.2.7_sass@1.72.0/node_modules/vite/dist/node/chunks/dep-C-KAszbv.js:48301:17)
    at resolvePackageEntry (/home/Dschungelabenteuer/vite-plugin-entry-shaking/node_modules/.pnpm/vite@5.2.7_sass@1.72.0/node_modules/vite/dist/node/chunks/dep-C-KAszbv.js:48298:5)
    at tryNodeResolve (/home/Dschungelabenteuer/vite-plugin-entry-shaking/node_modules/.pnpm/vite@5.2.7_sass@1.72.0/node_modules/vite/dist/node/chunks/dep-C-KAszbv.js:48068:20)
    at resolveByViteResolver (/home/Dschungelabenteuer/vite-plugin-entry-shaking/node_modules/.pnpm/vite@5.2.7_sass@1.72.0/node_modules/vite/dist/node/chunks/dep-C-KAszbv.js:68469:32)
    at eval (/home/Dschungelabenteuer/vite-plugin-entry-shaking/node_modules/.pnpm/vite@5.2.7_sass@1.72.0/node_modules/vite/dist/node/chunks/dep-C-KAszbv.js:68501:40)
    at requestCallbacks.on-resolve (/home/Dschungelabenteuer/vite-plugin-entry-shaking/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/lib/main.js:1364:28)
    at handleRequest (/home/Dschungelabenteuer/vite-plugin-entry-shaking/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/lib/main.js:722:17)
    at handleIncomingPacket (/home/Dschungelabenteuer/vite-plugin-entry-shaking/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/lib/main.js:747:7)
    at Socket.readFromStdout (/home/Dschungelabenteuer/vite-plugin-entry-shaking/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/lib/main.js:670:7)
    at EventEmitter.emit (node:events:42:9202)

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

    ../../node_modules/.pnpm/vite@5.2.7_sass@1.72.0/node_modules/vite/dist/node/chunks/dep-C-KAszbv.js:68486:26:
      68486 │                         const contents = await fsp.readFile(arg...
            ╵                           ^

    at setup (/home/Dschungelabenteuer/vite-plugin-entry-shaking/node_modules/.pnpm/vite@5.2.7_sass@1.72.0/node_modules/vite/dist/node/chunks/dep-C-KAszbv.js:68486:27)
    at handlePlugins (/home/Dschungelabenteuer/vite-plugin-entry-shaking/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/lib/main.js:1283:21)
    at buildOrContextImpl (/home/Dschungelabenteuer/vite-plugin-entry-shaking/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/lib/main.js:969:5)
    at Object.buildOrContext (/home/Dschungelabenteuer/vite-plugin-entry-shaking/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/lib/main.js:778:5)
    at eval (/home/Dschungelabenteuer/vite-plugin-entry-shaking/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/lib/main.js:2021:15)
    at Object.build (/home/Dschungelabenteuer/vite-plugin-entry-shaking/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/lib/main.js:2020:25)
    at Module.build (/home/Dschungelabenteuer/vite-plugin-entry-shaking/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/lib/main.js:1853:51)
    at bundleConfigFile (/home/Dschungelabenteuer/vite-plugin-entry-shaking/node_modules/.pnpm/vite@5.2.7_sass@1.72.0/node_modules/vite/dist/node/chunks/dep-C-KAszbv.js:68445:35)

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

    vite.config.ts:5:31:
      5 │ import EntryShakingPlugin from 'vite-plugin-entry-shaking';
        ╵                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~

failed to load config from /home/Dschungelabenteuer/vite-plugin-entry-shaking/examples/ballsack/vite.config.ts
error when starting dev server:
Error: Build failed with 1 error:
../../node_modules/.pnpm/vite@5.2.7_sass@1.72.0/node_modules/vite/dist/node/chunks/dep-C-KAszbv.js:48301:9: ERROR: [plugin: externalize-deps] Failed to resolve entry for package "vite-plugin-entry-shaking". The package may have incorrect main/module/exports specified in its package.json.
    at failureErrorWithLog (/home/Dschungelabenteuer/vite-plugin-entry-shaking/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/lib/main.js:1641:15)
    at eval (/home/Dschungelabenteuer/vite-plugin-entry-shaking/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/lib/main.js:1049:25)
    at runOnEndCallbacks (/home/Dschungelabenteuer/vite-plugin-entry-shaking/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/lib/main.js:1476:45)
    at buildResponseToResult (/home/Dschungelabenteuer/vite-plugin-entry-shaking/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/lib/main.js:1047:7)
    at eval (/home/Dschungelabenteuer/vite-plugin-entry-shaking/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/lib/main.js:1076:16)
    at responseCallbacks.<computed> (/home/Dschungelabenteuer/vite-plugin-entry-shaking/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/lib/main.js:694:9)
    at handleIncomingPacket (/home/Dschungelabenteuer/vite-plugin-entry-shaking/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/lib/main.js:754:9)
    at Socket.readFromStdout (/home/Dschungelabenteuer/vite-plugin-entry-shaking/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/lib/main.js:670:7)
    at EventEmitter.emit (node:events:42:9202)
    at addChunk (node:internal/streams/readable:105:4109)
 ELIFECYCLE  Command failed with exit code 1.

To Reproduce

Click on https://pr.new/Dschungelabenteuer/vite-plugin-entry-shaking and you'll see the first issue. Generate a new package and run dev and you'll see the next one

Vite version

Latest

Additional context

None

Dschungelabenteuer commented 6 months ago

Thanks for reporting! It should be fixed now :-)