simeydotme / svelte-range-slider-pips

Multi-Thumb, Accessible, Beautiful Range Slider with Pips
https://simeydotme.github.io/svelte-range-slider-pips/
Mozilla Public License 2.0
464 stars 44 forks source link

[bug] Warning about svelte field in package.json (sveltekit v2, vite v5) #125

Closed 0gust1 closed 2 months ago

0gust1 commented 10 months ago

Describe the bug

First, thanks for the work!

With the upgrade of our project to sveltekit v2, we now have a warning about this package.

[vite-plugin-svelte] WARNING: The following packages have a svelte field in their package.json but no exports condition for svelte.
...
svelte-range-slider-pips@2.2.3
...

Please see https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#missing-exports-condition for details.

The link https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#missing-exports-condition hints toward the solution.

It seems pretty straightforward (and also backward compatible), nevertheless, feel free to tell if further info and/or a PR could help !

To Reproduce

Create a fresh svelte + vite v5 project or a fresh sveltekit v2 project, and import svelte-range-slider-pips. npm run dev or npm run build will show the warning.

simeydotme commented 10 months ago

thanks!

hmm, I have another open issue regarding warnings, too. But the same issue exists; I have to research how to build a svelte component into a JS standalone component in the newer versions of svelte. It looks like the svelte-component template hasn't updated for many years and since the move to Vite I have no idea how to configure the outputs. This was built in the Rollup era.

I'll try to spend some time learning how to use Vite like a bundler. As I really absolutely need to maintain the ability to export as a .js file which works with vanilla, vue & react.

serferdinand2 commented 10 months ago

Hi, I believe we found the solution for the warning and an error. Just try putting this in the package.json:

  "exports": {
    ".": {
      "svelte": "./dist/svelte-range-slider-pips.mjs"
    }
  },

We also had this error:


  [vite-plugin-svelte] WARNING: The following packages have a svelte field in their package.json but no exports condition for svelte.

svelte-range-slider-pips@2.2.3

Please see https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#missing-exports-condition for details.
[...]

Error when evaluating SSR module /node_modules/svelte-range-slider-pips/src/index.js: failed to import "/node_modules/svelte-range-slider-pips/src/RangeSlider.svelte"
|- TypeError: Cannot read properties of undefined (reading 'value')
    at TemplateLiteral (file:///Users/jw/Work/surveyplanet/app_v2/node_modules/esrap/src/handlers.js:1154:26)
    at handle (file:///Users/jw/Work/surveyplanet/app_v2/node_modules/esrap/src/handlers.js:57:2)
    at CallExpression|NewExpression (file:///Users/jw/Work/surveyplanet/app_v2/node_modules/esrap/src/handlers.js:516:4)
    at handle (file:///Users/jw/Work/surveyplanet/app_v2/node_modules/esrap/src/handlers.js:57:2)
    at TemplateLiteral (file:///Users/jw/Work/surveyplanet/app_v2/node_modules/esrap/src/handlers.js:1157:4)
    at handle (file:///Users/jw/Work/surveyplanet/app_v2/node_modules/esrap/src/handlers.js:57:2)
    at AssignmentExpression (file:///Users/jw/Work/surveyplanet/app_v2/node_modules/esrap/src/handlers.js:632:3)
    at handle (file:///Users/jw/Work/surveyplanet/app_v2/node_modules/esrap/src/handlers.js:57:2)
    at ExpressionStatement (file:///Users/jw/Work/surveyplanet/app_v2/node_modules/esrap/src/handlers.js:796:3)
    at handle (file:///Users/jw/Work/surveyplanet/app_v2/node_modules/esrap/src/handlers.js:57:2)

Let me know if that works. It worked for us when we edited the nodemodule.

simeydotme commented 9 months ago

hey @serferdinand2 / @0gust1 do you mind to try with the beta version I just published? https://www.npmjs.com/package/svelte-range-slider-pips/v/3.0.0-beta.3 see if that is working?

I updated to svelte4 and added types and other small improvements. Haven't updated readme yet

himynameisdave commented 8 months ago

@simeydotme Tried the beta version and can confirm that the errors are gone!

0gust1 commented 8 months ago

@simeydotme

I just tried 3.0.0-beta.5 and 3.0.0-beta.3.

I can confirm that in both cases the warning mentionned above is gone.

But, we have a build error in our project (sorry):

error during build:
RollupError: src/lib/components/XXX/XXX/XXX.svelte (2:8): "default" is not exported by "node_modules/svelte-range-slider-pips/dist/svelte/index.js", imported by "src/lib/components/XXX/XXX/XXX.svelte".
file: /Absolute/path/to/workspace/file/src/lib/components/XXX/XXX/XXX.svelte:2:8
1: <script lang="ts">
2:   import RangeSlider from 'svelte-range-slider-pips';
            ^
3:   import PlotTrendGraph from './PlotTrendGraph.svelte';

Detailed versions used:

0gust1 commented 8 months ago

@simeydotme

FYI, our build error goes away if we change the import to import { RangeSlider } from 'svelte-range-slider-pips';

IDK if it's normal or intended.

simeydotme commented 8 months ago

@simeydotme

FYI, our build error goes away if we change the import to import { RangeSlider } from 'svelte-range-slider-pips';

IDK if it's normal or intended.

Yes, I expect this to be the new way to import, will have to update documentation. Because I moved it over to a SvelteKit lib, and separated all the logic and functions, should help with tree-shaking and optimising code. Also it was necessary to allow usage with the new package exports and jQuery/Vanilla

https://github.com/simeydotme/svelte-range-slider-pips/blob/v3.0.0-beta.3/src/lib/index.ts

I'll see if I can get it out this weekend :)

simeydotme commented 8 months ago

thanks for your effort to help!

thibistaken commented 5 months ago

Hi! I face the same issue. Would you have any update on the 3.0 rollout? Thanks for your work on this.

jamiegau commented 3 months ago

Yes, this issue has existed for a long time. Can we get a point release with this change to packages to remove this warning please.

simeydotme commented 3 months ago

Yes, this issue has existed for a long time. Can we get a point release with this change to packages to remove this warning please.

hi, not sure what you mean by point release I will not change build process and exports fields without a major release because it could break infra/build (especially just for a warning in some build processes)

But I'll yolo out 3.0.0 asap, which should also make it future compatible with svelte 5

jamiegau commented 3 months ago

A point release meaning. 2.3.1, and all it does over 2.3.0 is add the few lines needed in the packages.json file that makes the warning disappear. Otherwise, if days away. Whatever..

simeydotme commented 2 months ago

Should be resolved by #145