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

Sveltejs/kit 1.0.0-next.526 and above Incompatible with svelte-jsoneditor #185

Closed
ZaxyxaZ opened this issue Nov 3, 2022 · 20 comments
Closed
Labels
bug Something isn't working

Comments

@ZaxyxaZ
Copy link

ZaxyxaZ commented Nov 3, 2022

Updating to the latest version of "sveltejs/kit" above 1.0.0-next.525 version results in error while working with "svelte-jsoneditor" , The following error is displayed on the chrome developer console and app fails to start:

image

SyntaxError: The requested module '/node_modules/json-source-map/index.js?v=fda884be' does not provide an export named 'default' (at jsonUtils.js?v=fda884be:2:8)

Also surfaces in VSCode console as E:/dev/src/sveltekit/example-app/node_modules/ajv-dist/dist/ajv7.min.js" points to missing source files. As a result - the application never starts.

@josdejong
Copy link
Owner

Thanks for reporting.

I created a fresh new sveltekit project (with @sveltejs/kit@1.0.0-next.532), installed svelte-jsoneditor, add the
<JSONEditor ... /> component in +page.svelte (using VS Code), started a dev server, and opened it in Chrome. I do not see any of the warnings that you report so I guess I'm missing something?

How can I reproduce this issue?

@ZaxyxaZ
Copy link
Author

ZaxyxaZ commented Nov 6, 2022 via email

@josdejong
Copy link
Owner

Is it possible to create a minimal demo of the problem? Like a codesandbox example or so?

@ZaxyxaZ
Copy link
Author

ZaxyxaZ commented Nov 6, 2022

Additional debug information from browser console:

client-manifest.js:18 SyntaxError: The requested module '/node_modules/json-source-map/index.js?v=e2e2c781' does not provide an export named 'default' (at jsonUtils.js?v=e2e2c781:2:8)

In the referenced source file:

import jsonSourceMap from '/node_modules/json-source-map/index.js?v=e2e2c781'; (Shows error)

@seandlg
Copy link

seandlg commented Nov 6, 2022

I'm seeing the same issue, but struggling to reproduce it. Will post an update once I manage to reproduce something..

@seandlg
Copy link

seandlg commented Nov 6, 2022

It looks to me like a weird race condition. I can sometimes trigger the issue, by toggling SSR at the +layout.js-level, but I can't make it reproducible. I suspect it is related to vitejs.. In the course of debugging the issue, I did notice a wrong type import from svelte-jsoneditor, so I cannot rule out that this played a part..

@ZaxyxaZ
Copy link
Author

ZaxyxaZ commented Nov 6, 2022 via email

@ZaxyxaZ
Copy link
Author

ZaxyxaZ commented Nov 6, 2022 via email

@josdejong
Copy link
Owner

I can sometimes trigger the issue, by toggling SSR at the +layout.js-level

I did try that out, but still can't reproduce this at all 🤔 .

In the course of debugging the issue, I did notice a wrong type import from svelte-jsoneditor

Is this an issue in the library? If so, what is the bug? That sounds like easily solvable

@gauravrawat440
Copy link

that
well @seandlg is right about the toggling the ssr at +layout.js , toggling it seems to have resolved the issue. The issue occurs from the dependency that is "json-source-map". the error is as follows:

SyntaxError: The requested module '/node_modules/json-source-map/index.js?v=fda884be' does not provide an export named 'default

@ZaxyxaZ
Copy link
Author

ZaxyxaZ commented Nov 7, 2022

I think we have nailed down the issue to some sort of Vite compilation / dependency issue. The problem can be resolved after toggling SSR. First, you have to wait for the failure. Then go into the source (+layout.js) and reset to the opposite value (in our case true) and then when the application error resolves restart the server and it works. Here is terminal output from Vite.

[vite] ✨ new dependencies optimized: immutable-json-patch, lodash-es, @fortawesome/free-regular-svg-icons, ajv-dist, jmespath, ...and 16 more
2:44:54 PM [vite] ✨ optimized dependencies changed. reloading

Clearly this "optimization" needs to occur prior to a failure.

@ZaxyxaZ
Copy link
Author

ZaxyxaZ commented Nov 7, 2022

@josdejong Looks like this is a Vite dev mode issue not resolving all dependencies. If any one else has issues just build and preview the app.

@bluwy
Copy link

bluwy commented Nov 8, 2022

I'm guessing svelte-jsoneditor is being added to optimizeDeps.exclude in vite.config.js? (Should be removed) Otherwise we'd need a repro to look into this.

@josdejong
Copy link
Owner

I've had quite some issues related to non-ESM dependencies in the past, in the early days of SvelteKit+Vite, see for example this workaround: #121 (comment). I haven't seen much issues lately though.

Does a workaround with optimizeDeps.exclude work in this case?

@ZaxyxaZ
Copy link
Author

ZaxyxaZ commented Nov 8, 2022

@josdejong I think you were on the right track. The exclude parameter had no effect. And the messages out of Vite led me to think including up front might have an effect. I started adding the modules that Vite was reoptimizing one by one and this combination has addressed the dependency issue. Obviously, there is still a Vite issue to be dealt with but now there is at least a decent temporary work around. Added to vite.config.js:

  optimizeDeps: {
    include: [
      'ajv-dist', 
      'immutable-json-patch',
      'lodash-es',
      '@fortawesome/free-regular-svg-icons',
      'jmespath'
    ]
  }

@josdejong
Copy link
Owner

ahh, wow, that helps a lot! Thanks for sharing this workaround.

This makes sense (though it is a pity that this workaround is needed). I'm a bit surprised that for example lodash-es is needed, since that is a modern ESM only package.

@seandlg
Copy link

seandlg commented Nov 9, 2022

@josdejong I think you were on the right track. The exclude parameter had no effect. And the messages out of Vite led me to think including up front might have an effect. I started adding the modules that Vite was reoptimizing one by one and this combination has addressed the dependency issue. Obviously, there is still a Vite issue to be dealt with but now there is at least a decent temporary work around. Added to vite.config.js:

  optimizeDeps: {
    include: [
      'ajv-dist', 
      'immutable-json-patch',
      'lodash-es',
      '@fortawesome/free-regular-svg-icons',
      'jmespath'
    ]
  }

This does not work for me, but you are right in the observation that the bug seems to be devserver related. I guess I'll wait for a few days/weeks and see if the problem evaporates with further updates to vite, since I fail to create a reproducible example 🤷

In the course of debugging the issue, I did notice a wrong type import from svelte-jsoneditor

Is this an issue in the library? If so, what is the bug? That sounds like easily solvable

This was a mistake on my end. svelte-jsoneditor is awesome! :-)

@ZaxyxaZ
Copy link
Author

ZaxyxaZ commented Nov 9, 2022

ahh, wow, that helps a lot! Thanks for sharing this workaround.

This makes sense (though it is a pity that this workaround is needed). I'm a bit surprised that for example lodash-es is needed, since that is a modern ESM only package.

Don't disagree - but was only following the bread crumbs left by the console output from Vite. I will say @seandlg that this fix is very specific to the set of packages we are using. As such the exact includes will be different if others run into this same issue.

@AlexRMU
Copy link

AlexRMU commented Nov 10, 2022

It didn't help me either. Maybe you need to create a issue in vite?

@josdejong
Copy link
Owner

I've described the workaround for this issue in the readme in a new section "Known issues". Besides that, I don't think this issue is actionable, I'll close this issue now. Feel free to reopen if needed.

@josdejong josdejong added the bug Something isn't working label Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants