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

Vite import error #121

Closed
AlexRMU opened this issue Aug 12, 2022 · 9 comments
Closed

Vite import error #121

AlexRMU opened this issue Aug 12, 2022 · 9 comments

Comments

@AlexRMU
Copy link

AlexRMU commented Aug 12, 2022

"@sveltejs/kit": "1.0.0-next.405",
"svelte-jsoneditor": "^0.6.2",
"vite": "^3.0.6"

An error appears when importing the editor (even if using vite-plugin-iso-import):
The requested module '/node_modules/.pnpm/immutable-json-patch@3.0.0/node_modules/immutable-json-patch/lib/umd/immutableJSONPatch.js?v=e94066c2' does not provide an export named 'compileJSONPointer'

The problem is that vite imports immutable-json-patch from umd instead of es (https://github.com/josdejong/immutable-json-patch/blob/main/package.json#L12)

@ZaxyxaZ
Copy link

ZaxyxaZ commented Aug 12, 2022

I can confirm this is an issue with versions of Vite greater than 3.0.0 - If you revert to Vite 3.0.0 it does find the dependency.

@AlexRMU
Copy link
Author

AlexRMU commented Aug 13, 2022

It doesn't work for me on 3.0.0 either

@seandlg
Copy link

seandlg commented Aug 15, 2022

I'm seeing this issue, too.

@seandlg
Copy link

seandlg commented Aug 15, 2022

A probably really hacky workaround is to pre-bundle some dependencies (vite.config.js):

import { sveltekit } from '@sveltejs/kit/vite';

/** @type {import('vite').UserConfig} */
const config = {
	plugins: [sveltekit()],
	optimizeDeps: {
		include: [
			'svelte-jsoneditor',
			'immutable-json-patch',
			'json-source-map',
			'classnames',
			'natural-compare-lite',
			'ajv-dist'
		]
	}
};

export default config;

Not quite sure what I'm up against here, but it works for now..

@josdejong
Copy link
Owner

Thanks for reporting. It's a bit of a whac-a-mole thing with SvelteKit in beta, just switched to Vite@3, ES / CommonJS hybrid cases, and plenty of different build tools. Maybe we're a bit too much on the bleading edge of development 😁.

How can I reproduce this issue exactly?

I just tried the following:

  • Create a new sveltekit project with npm create svelte@latest test-svelte-jsoneditor
  • Update all dependencies to the latest version, and remove ^to install exact versions
  • npm install svelte-jsoneditor
  • Create a minimal page using the editor:
    <script>
      import { JSONEditor } from "svelte-jsoneditor";
    
      let content = {
        json: [1, 2, 3],
      };
    </script>
    
    <JSONEditor {content} />
  • This works fine when running the development server npm run dev
  • When building the project via npm run build I'm hitting an other known CommonJS related issue, Dependency issue with fortawesome building svelte-kit #107, but not the one you're mentioning above.

From your example trace it looks like you're using pnpm, but funny enough both dev and build work when having installed via pnpm 😕 .

@seandlg
Copy link

seandlg commented Aug 18, 2022

You're right, I just followed the same procedure and didn't encounter the error anymore! I checked which version of sveltekit I'm using, and it is 1.0.0-next.405, so I suppose the fix might've happend in the last couple of versions (right now there's 1.0.0-next.420). I guess you're right - stuff breaks when you're at the bleeding edge 😅 So cool at the same time though - allow me to drop in some huge thanks for your awesome software!

@josdejong
Copy link
Owner

Good to hear, thanks!

@AlexRMU
Copy link
Author

AlexRMU commented Aug 19, 2022

I updated vite and everything worked

@AlexRMU AlexRMU closed this as completed Aug 19, 2022
@josdejong
Copy link
Owner

😅👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants