Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix this plugin with vite dev server #202

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

dreuter
Copy link

@dreuter dreuter commented Oct 14, 2024

Hey :)

First of all: Thanks for this great project. Has already proven useful to me :)

However 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.

I thought I would open a CR, so that other people using this plugin with vite don't run into the same problem :)

Copy link

changeset-bot bot commented Oct 14, 2024

🦋 Changeset detected

Latest commit: 447fc60

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
rollup-plugin-sizes Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant