Skip to content

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

Closed

Description

@ZaxyxaZ

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.

Activity

  1. josdejong commented on Nov 4, 2022

    @josdejong
    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?

  2. ZaxyxaZ commented on Nov 6, 2022

    @ZaxyxaZ
    Author
  3. josdejong commented on Nov 6, 2022

    @josdejong
    Owner

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

  4. ZaxyxaZ commented on Nov 6, 2022

    @ZaxyxaZ
    Author

    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)

  5. seandlg commented on Nov 6, 2022

    @seandlg

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

  6. seandlg commented on Nov 6, 2022

    @seandlg

    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..

  7. ZaxyxaZ commented on Nov 6, 2022

    @ZaxyxaZ
    Author
  8. ZaxyxaZ commented on Nov 6, 2022

    @ZaxyxaZ
    Author
  9. josdejong commented on Nov 7, 2022

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

  10. gauravrawat440 commented on Nov 7, 2022

    @gauravrawat440

    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

  11. ZaxyxaZ commented on Nov 7, 2022

    @ZaxyxaZ
    Author

    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.

  12. ZaxyxaZ commented on Nov 7, 2022

    @ZaxyxaZ
    Author

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

  13. bluwy commented on Nov 8, 2022

    @bluwy

    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.

  14. josdejong commented on Nov 8, 2022

    @josdejong
    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?

  15. ZaxyxaZ commented on Nov 8, 2022

    @ZaxyxaZ
    Author

    @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'
        ]
      }
  16. josdejong commented on Nov 9, 2022

    @josdejong
    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.

  17. seandlg commented on Nov 9, 2022

    @seandlg

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

  18. ZaxyxaZ commented on Nov 9, 2022

    @ZaxyxaZ
    Author

    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.

  19. AlexRMU commented on Nov 10, 2022

    @AlexRMU

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

  20. josdejong commented on Dec 6, 2022

    @josdejong
    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions