Skip to content

Commit

Permalink
Fix this plugin with vite dev server
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dreuter committed Oct 14, 2024
1 parent 5575c8f commit cba646b
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ module.exports = (options) => {
input = original;
} else if(typeof original === "object") {
input = Object.values(original);
} else if(typeof original === "undefined") {
input = [];
} else {
input = [ original ];
}
Expand Down

0 comments on commit cba646b

Please sign in to comment.