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

In examples, add "svelte" to conditions in esbuild build options #183

Merged
merged 2 commits into from
Jun 26, 2023

Conversation

BlueGreenMagick
Copy link
Contributor

Problem

Currently, when you try to import a svelte component library, you get the below error when building.

None of the conditions provided ("types", "svelte") match any of the currently active conditions
  ("browser", "default", "import", "module"):

Steps to reproduce:

  1. npx degit EMH333/esbuild-svelte/example-ts my-svelte-app
  2. npm install svelte-french-toast
  3. Add statement import toast from "svelte-french-toast" to code.
  4. npm install, npm run build

Solution

The solution is to add conditions: ["svelte"], to esbuild's build options. I had problem figuring it out as I couldn't find this information anywhere. So I added this information to examples in README and example projects.

Svelte plugins for other bundlers like rollup and webpack all state this information in their READMEs:
https://github.com/sveltejs/rollup-plugin-svelte#svelte-exports-condition
https://github.com/sveltejs/svelte-loader#resolveconditionnames

@EMH333
Copy link
Owner

EMH333 commented Jun 23, 2023

Ah yep, thanks for documenting that. Do you think this is the sort of thing that esbuild-svelte should add automatically? This seems reasonable along with the change to condition handling for svelte@v4

breaking: Bundlers must specify the browser condition when building a frontend bundle for the browser (sveltejs/svelte#8516)

Please fix the linting issue, I'll merge after that!

This is needed to import svelte component libraries
@BlueGreenMagick
Copy link
Contributor Author

BlueGreenMagick commented Jun 24, 2023

Fixed!

Do you think this is the sort of thing that esbuild-svelte should add automatically?

I'm not sure about that either. But the other svelte plugins for rollup and webpack all require manually setting it up, so keeping it that way seemed safer.

breaking: Bundlers must specify the browser condition when building a frontend bundle for the browser (sveltejs/svelte#8516)

Should I add something for this? esbuild automatically include it in conditions if platform is set to "browser"
https://esbuild.github.io/api/#how-conditions-work

@EMH333
Copy link
Owner

EMH333 commented Jun 25, 2023

I'm not sure about that either. But the other svelte plugins for rollup and webpack all require manually setting it up, so keeping it that way seemed safer.

Fair enough. I'll keep an eye on it and might consider changing that in a breaking release at some point.

Should I add something for this?

Yeah if you would be willing to add a mention about it that would be great! I'll merge this PR on Monday evening either way. Thanks!

@BlueGreenMagick
Copy link
Contributor Author

Yeah if you would be willing to add a mention about it that would be great!

Done!

@EMH333 EMH333 merged commit d800329 into EMH333:main Jun 26, 2023
4 checks passed
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.

None yet

2 participants