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

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

Open
0gust1 opened this issue Dec 27, 2023 · 8 comments · May be fixed by #129
Open

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

0gust1 opened this issue Dec 27, 2023 · 8 comments · May be fixed by #129
Labels
bug Something isn't working investigating Not quite sure if it's valid, yet

Comments

@0gust1
Copy link

0gust1 commented Dec 27, 2023

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.

@0gust1 0gust1 added bug Something isn't working investigating Not quite sure if it's valid, yet labels Dec 27, 2023
@simeydotme
Copy link
Owner

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
Copy link

serferdinand2 commented Jan 8, 2024

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
Copy link
Owner

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

@simeydotme simeydotme added this to the Svelte 4+ , Typescript milestone Feb 28, 2024
@himynameisdave
Copy link

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

@0gust1
Copy link
Author

0gust1 commented Mar 19, 2024

@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:

  • @sveltejs/kit@2.5.4
  • @sveltejs/vite-plugin-svelte@3.0.2
  • svelte@4.2.12
  • vite@5.1.6
  • svelte-range-slider-pips@3.0.0-beta.5 (problem also present with 3.0.0-beta.3)

@0gust1
Copy link
Author

0gust1 commented Mar 19, 2024

@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
Copy link
Owner

simeydotme commented Mar 19, 2024

@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
Copy link
Owner

thanks for your effort to help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working investigating Not quite sure if it's valid, yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants