Crash on build
Closed this issue · 6 comments
I can't get it to work on a freshly created SvelteKit project.
Excuse me if it's just a knowledge gap and I am missing what this project is actually for.
Steps to reproduce:
npm create svelte@latest my-app
- add vite-bundle-analyzer to
vite.config.ts
npm run build
error during build:
TypeError: Cannot read properties of null (reading 'port')
at get port [as port] (file:///Users/peter/code/local-first/vite-bundle-test/node_modules/.pnpm/vite-bundle-analyzer@0.9.4/node_modules/vite-bundle-analyzer/dist/index.mjs:2:7940)
at Object.closeBundle (file:///Users/peter/code/local-first/vite-bundle-test/node_modules/.pnpm/vite-bundle-analyzer@0.9.4/node_modules/vite-bundle-analyzer/dist/index.mjs:2:10477)
at file:///Users/peter/code/local-first/vite-bundle-test/node_modules/.pnpm/rollup@4.17.2/node_modules/rollup/dist/es/shared/node-entry.js:19778:40
at async Promise.all (index 0)
at async PluginDriver.hookParallel (file:///Users/peter/code/local-first/vite-bundle-test/node_modules/.pnpm/rollup@4.17.2/node_modules/rollup/dist/es/shared/node-entry.js:19706:9)
at async Object.close (file:///Users/peter/code/local-first/vite-bundle-test/node_modules/.pnpm/rollup@4.17.2/node_modules/rollup/dist/es/shared/node-entry.js:20635:13)
at async build (file:///Users/peter/code/local-first/vite-bundle-test/node_modules/.pnpm/vite@5.2.11/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:67497:13)
at async CAC.<anonymous> (file:///Users/peter/code/local-first/vite-bundle-test/node_modules/.pnpm/vite@5.2.11/node_modules/vite/dist/node/cli.js:842:9)
You can also check out the codesandbox or the minimal repo showcasing the error.
This plugin is same as webpack-bundle-analyzer
. It's a tool for user to analyze their application. For example, detecting whether there are duplicate dependencies and etc. And you're using svelte-kit
. The panic info may cause by build race condition. Usually we often using Promise.all(tasks)
to perf logic. I think svelte-kit is same. So you only set analyzerMode: "static"
for this plugin. and got the result in your output directory.
Can confirm it works in static mode.
I had the same error but it was because I already had something else running on the same port.
I guess server.address()
is null
at this line if the server.listen
fails.
vite-bundle-analyzer/src/server/server.ts
Line 72 in 38891dc
I'm afraid not, AFAIK most of based on vite's ssr framework have two task. One is build client the other is build server. I guess the plugin is run twice by them. Usually, when running two tasks concurrently, Promise.all
is used to execute them. Consequently, so it's possible that one of the processes was abnormally closed. affecting the get port.
BTW, I think i got something wrong. This problem will be fix soon.
Now the v0.10.1
has been released. Check it.