Skip to content

Fix ESM import in core package by adding .babelrc and babel-plugin-add-import-extension #732

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

Merged
merged 1 commit into from
May 1, 2025

Conversation

Shellishack
Copy link
Contributor

@Shellishack Shellishack commented Apr 30, 2025

This fixes issues from #731.

Here is the codesandbox that implements this https://codesandbox.io/p/github/Shellishack/webpack-esm-sandbox/fork-fix. After adding the babel plugin, core builds for ESM contains ".js" suffix in import clauses. So webpack no longer complains things like:

ERROR in ./node_modules/@uiw/react-codemirror/esm/index.js 5:0-48
Module not found: Error: Can't resolve './useCodeMirror' in 'C:\GitHub\pulse-editor-code-view\node_modules\@uiw\react-codemirror\esm'
Did you mean 'useCodeMirror.js'?

This might be a fix only for Webpack (I am only familiar with Webpack). May need more testing for Vite, etc.

I am sure if adding a babel plugin in this case would be the most appropriate solution, since it was the building tool that did not include file extensions in imports. Is it a behavior from tsbb causing this issue? LMK what you think.

@jaywcjlove
Copy link
Member

image

Thank you for your PR submission. After testing, everything works fine.

@jaywcjlove jaywcjlove merged commit 9a5ce28 into uiwjs:master May 1, 2025
github-actions bot pushed a commit that referenced this pull request May 1, 2025
jaywcjlove added a commit to jaywcjlove/tsbb that referenced this pull request May 1, 2025
jaywcjlove added a commit to jaywcjlove/tsbb that referenced this pull request May 1, 2025
github-actions bot added a commit to jaywcjlove/tsbb that referenced this pull request May 1, 2025
jaywcjlove added a commit to jaywcjlove/tsbb that referenced this pull request May 1, 2025
jaywcjlove added a commit that referenced this pull request May 1, 2025
jaywcjlove added a commit that referenced this pull request May 1, 2025
github-actions bot pushed a commit that referenced this pull request May 1, 2025
@jaywcjlove
Copy link
Member

@Shellishack thx! I refactored the babel-plugin-add-import-extension package and integrated it into the tsbb build tool, effectively solving similar issues across all dependencies.

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

Successfully merging this pull request may close these issues.

2 participants