EMH333 / esbuild-svelte

An esbuild plugin to compile Svelte components
https://www.npmjs.com/package/esbuild-svelte
MIT License
245 stars 24 forks source link

Svelte 5 Pre-release Compatibility #235

Closed EMH333 closed 1 month ago

EMH333 commented 6 months ago

This is different than #234 since npm does some funny things with version locks and the prerelease versions may have subtle changes compared to the actual release.

This is a good time to clarify my commitment to prerelease support:

  1. I promise that esbuild-svelte will have an installable version compatible with Svelte 5 the day it is released. It may not support all the new features, but it will at least let projects compile with Svelte 5. Worth noting that I am intending v0.8.1 to be that version, but won't hesitate to make changes as required.
  2. Support for prereleases is best effort only and will stop immediately (and retroactively) once a production version of Svelte 5 is released.
  3. The usual DX does not exist for prerelease versions (see below) since they are, well, prerelease. Hacky workarounds may be required, with the expectation that they go away on the release of Svelte 5.
EMH333 commented 6 months ago

I'm not sure if I'm doing something wrong, but I'm seeing this when I run npm install.

$ npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: project@undefined
npm ERR! Found: svelte@5.0.0-next.136
npm ERR! node_modules/svelte
npm ERR!   dev svelte@"^5.0.0-next.136" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer svelte@">=3.43.0 <6" from esbuild-svelte@0.8.1
npm ERR! node_modules/esbuild-svelte
npm ERR!   dev esbuild-svelte@"^0.8.1" from the root project

My package.json looks like this.

{
  "name": "project",
  "devDependencies": {
    "esbuild": "^0.21.0",
    "esbuild-svelte": "^0.8.1",
    "svelte": "^5.0.0-next.136"
  }
}

I updated to the latest esbuild-svelte and installed svelte@next.

EMH333 commented 6 months ago

TL;DR: Use --force or --legacy-peer-deps for the prereleases since there isn't a great way to allow peer dependencies of all prerelease versions of a package.

Essentially, semver doesn't consider prereleases of v5 to be <6. As a result, even though the human-readable version number of 5.0.0-next.1 is clearly less than v6, semver doesn't consider that to be the case (try it out with https://semver.npmjs.com/). This means that dependency graph solving fails.

There are numerous issues about this (https://github.com/npm/cli/issues/2087 as an example) and an active RFC on how to resolve this https://github.com/npm/rfcs/pull/397.

But I don't think there is a clear/easy way to fix this for the prerelease versions. This won't be an issue once Svelte 5 is officially released.

tgf9 commented 6 months ago

Excellent! Thanks for the detailed answer! I didn't realize this was a known behavior with npm. Good to know. Adding --force worked! Project builds and runs fine now.

tgf9 commented 5 months ago

Would it make sense to change esbuild-svelte's package.json to this?

  "peerDependencies": {
    "esbuild": ">=0.9.6",
-    "svelte": ">=3.43.0 <6"
+    "svelte": ">=3.43.0 <5 || ^5.0.0-next.0"
  },

Then later, when Svelte 5 officially releases, maybe you could do this?

  "peerDependencies": {
    "esbuild": ">=0.9.6",
-    "svelte": ">=3.43.0 <5 || ^5.0.0-next.0"
+    "svelte": ">=3.43.0 <5 || ^5.0.0-next.0 || ^5.0.0"
  },

I think this could improve the DX by not requiring that users pass --force to npm install. Also, this is how svelte-check does it.

EMH333 commented 3 months ago

Interesting! Let me play around with that and see what I can do

EMH333 commented 2 months ago

The change to allow Svelte 5 pre-releases as a peer dependency has been released as v0.8.2. Sorry for the delay!

EMH333 commented 1 month ago

Svelte 5 has officially been released, meaning esbuild-svelte will no longer provide support or compatibility for prereleases. Closing this issue.