aidenybai / million

Optimize React performance and make your React 70% faster in minutes, not months.
https://million.dev
MIT License
15.89k stars 558 forks source link

`import with` broken by vite plugin #1013

Closed Idrinth closed 2 months ago

Idrinth commented 3 months ago

What version of million are you using?

3.0.6

Are you using an SSR adapter? If so, which one?

none

What package manager are you using?

npm

What operating system are you using?

Windows+Linux

What browser are you using?

Chromium, Firefox

Describe the Bug

import pkg from '../../../../package.json' with {
  type: 'json'
};

is compiled wrongly, breaking it, because the { and } get removed. This errors out in the following build step.

What's the expected result?

The plugin does not remove required curly braces

Link to Minimal Reproducible Example

https://stackblitz.com/edit/vitejs-vite-azcm9h

Participation

github-actions[bot] commented 3 months ago

Thanks for opening this issue! A maintainer will review it soon.

tobySolutions commented 3 months ago

Hello there @Idrinth, do you think you can provide a reproduction that I can have a look at and then present to the team if need be. You shouldn't be getting the above error at all.

Idrinth commented 3 months ago

terribly sorry if the example was too big. will put some time aside to build a smaller one tomorroe

Idrinth commented 3 months ago

Hello there @Idrinth, do you think you can provide a reproduction that I can have a look at and then present to the team if need be. You shouldn't be getting the above error at all.

https://stackblitz.com/edit/vitejs-vite-azcm9h

github-actions[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within the next 7 days.

Idrinth commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within the next 7 days.

That shouldn't be the case, issue is still unsolved to my knowledge.

tobySolutions commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within the next 7 days.

That shouldn't be the case, issue is still unsolved to my knowledge.

Hmm, thank you very much for this. Really appreciate this. Let me share this with the team. Sorry for the auto-labelling bot.

tobySolutions commented 2 months ago

Taking a look at your reproduction now.

tobySolutions commented 2 months ago

Ok, I fixed it @Idrinth; the issue isn't a Million issue at all. It's an issue with babel and vite I think. So, I did a bit of research around and found a fix:

https://stackblitz.com/edit/vitejs-vite-gm2ltv?file=vite.config.ts

Idrinth commented 2 months ago

Ok, I fixed it @Idrinth; the issue isn't a Million issue at all. It's an issue with babel and vite I think. So, I did a bit of research around and found a fix:

https://stackblitz.com/edit/vitejs-vite-gm2ltv?file=vite.config.ts

That is using the deprecated assert instead of with for the import. Can't replicate it working once I switch back to with.

tobySolutions commented 2 months ago

Ok, I fixed it @Idrinth; the issue isn't a Million issue at all. It's an issue with babel and vite I think. So, I did a bit of research around and found a fix:

https://stackblitz.com/edit/vitejs-vite-gm2ltv?file=vite.config.ts

That is using the deprecated assert instead of with for the import. Can't replicate it working once I switch back to with.

Oh yes, you are correct. However this issue has nothing to do with Million.

It still says the same thing when you remove Million from your codebase.

Idrinth commented 2 months ago

Ok, I fixed it @Idrinth; the issue isn't a Million issue at all. It's an issue with babel and vite I think. So, I did a bit of research around and found a fix: https://stackblitz.com/edit/vitejs-vite-gm2ltv?file=vite.config.ts

That is using the deprecated assert instead of with for the import. Can't replicate it working once I switch back to with.

Oh yes, you are correct. However this issue has nothing to do with Million.

It still says the same thing when you remove Million from your codebase.

In that case my small example is insufficient, will try to replicate the issue in something slightly bigger. My main project works without million and only breaks once adding it :(

Idrinth commented 2 months ago

more digging and it looks like there is no way on million's side to fix this. Will have to do some code replacements to byopass the vite issue I guess.

tobySolutions commented 2 months ago

Yes @Idrinth, thank you very much 🙌

Idrinth commented 2 months ago

Yes @Idrinth, thank you very much 🙌

was easier than expected, actually just needed to switch to the babel plugin instead - that worked out fine.