Skip to content

Commit a9db23c

Browse files
authored
Fix this plugin with vite dev server (#202)
When I was trying to use this plugin as a `vite` plugin, building the assets worked fine, but starting the dev server failed with the following message: ``` error when starting dev server: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined at Object.dirname (node:path:1346:5) at .../node_modules/rollup-plugin-sizes/index.js:68:48 at Array.map (<anonymous>) at Object.options (.../node_modules/rollup-plugin-sizes/index.js:68:27) at PluginContainer.resolveRollupOptions (file://.../node_modules/vite/dist/node/chunks/dep-DG6Lorbi.js:48895:23) at createPluginContainer (file://.../node_modules/vite/dist/node/chunks/dep-DG6Lorbi.js:48799:19) at _createServer (file://.../node_modules/vite/dist/node/chunks/dep-DG6Lorbi.js:62752:27) at async CAC.<anonymous> (file://.../node_modules/vite/dist/node/cli.js:735:20) ``` It seems when the dev server is started, the plugin will receive an empty (`{}`) config. This then leads to the above error. Handling this case explicitely solves the problem. The report is only printed when running `vite build`, but that is okay/preferable for my usecase.
1 parent bec37e9 commit a9db23c

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

.changeset/kind-pillows-smile.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"rollup-plugin-sizes": minor
3+
---
4+
5+
Made this plugin compatible with `vite`

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ module.exports = (options) => {
5757
input = original;
5858
} else if(typeof original === "object") {
5959
input = Object.values(original);
60+
} else if(typeof original === "undefined") {
61+
input = [];
6062
} else {
6163
input = [ original ];
6264
}

0 commit comments

Comments
 (0)