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

ESM import bug #189

Closed
mikiastilahun opened this issue Nov 10, 2022 · 4 comments
Closed

ESM import bug #189

mikiastilahun opened this issue Nov 10, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@mikiastilahun
Copy link

I am getting these errors when I try to use it in a svelte project with Webpack 5.

  • ERROR in ./node_modules/.pnpm/svelte-jsoneditor@0.9.2/node_modules/svelte-jsoneditor/logic/history.js 1:0-45
    Module not found: Error: Can't resolve '../utils/debug' in svelte-jsoneditor/logic'
    Did you mean 'debug.js'?

  • ERROR in ./node_modules/.pnpm/svelte-jsoneditor@0.9.2/node_modules/svelte-jsoneditor/plugins/value/components/utils/getValueClass.js 1:0-63
    Module not found: Error: Can't resolve '../../../../utils/typeUtils' in /svelte-jsoneditor/plugins/value/components/utils'
    Did you mean 'typeUtils.js'?

Any idea how to fix them?
Thanks in advance.

@josdejong
Copy link
Owner

Thanks, good point.

In the setup of svelte-jsoneditor this is no problem, since the dependencies are resolved using nodejs resolution.

Just wondering: does adding the missing .js extensions resolve the issues in your setup? It still does not make the library truely ESM, since there are nodejs dependencies involved which are not imported with an url but with the module name.

Your solution in #191 will solve the issue, but will not guard against future issues. I think we need something like an eslint rule which warns us against a missing .js extension. Is this something you can/want to look into?

Alternatively, it may be possible to configure the build tools (Typescript, Rollup, Babel) to make sure the generated files do have a proper .js extension.

@mikiastilahun
Copy link
Author

Yes, the issue is resolved after adding the missing .js extensions. For now, I'm able to use my forked version, but you are absolutely right that we need to configure the build processes to ensure this won't happen in the future. I can look into it more and get back to you.

@josdejong
Copy link
Owner

For now, I'm able to use my forked version

Good to know you have a temporary workaround. We can indeed merge your PR as is, but need a long term solution too.

I can look into it more and get back to you.

That would be great, thanks!

@josdejong josdejong added the bug Something isn't working label Mar 1, 2023
@josdejong
Copy link
Owner

I've setup the import/extensions eslint plugin to check for .js file extensions for all imports.

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

2 participants