-
Notifications
You must be signed in to change notification settings - Fork 110
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
Fix language files for Node+ESM #1377
base: develop
Are you sure you want to change the base?
Conversation
Performance comparison of head (152b0dd) vs base (67bae9e)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested the dist files in some more popular bundlers and here are the results:
- Vite ^5.1.4 - OK
- Parcel2 ^2.0.0 - Does not support "exports" so the language file has to be imported with
/es/
or/commonjs/
prefixes; - Webpack5 ^5.8.0 - OK
- Webpack4 ^4.42.0 - I getting an error. Seems the webpack has the problem with importing values from "chevrotain".
// /node_modules/hyperformula/es/parser/FormulaParser.mjs
import { EmbeddedActionsParser, EMPTY_ALT, Lexer, tokenMatcher } from 'chevrotain';
// EmbeddedActionsParser, EMPTY_ALT and others are missing
ERROR in ./node_modules/hyperformula/es/parser/FormulaParser.mjs 689:125-137
Can't import the named export 'tokenMatcher' from non EcmaScript module (only default export is available)
@ ./node_modules/hyperformula/es/parser/index.mjs
@ ./node_modules/hyperformula/es/ArraySize.mjs
@ ./node_modules/hyperformula/es/index.mjs
@ ./src/index.js
ERROR in ./node_modules/hyperformula/es/parser/FormulaParser.mjs 708:29-41
Can't import the named export 'tokenMatcher' from non EcmaScript module (only default export is available)
@ ./node_modules/hyperformula/es/parser/index.mjs
@ ./node_modules/hyperformula/es/ArraySize.mjs
@ ./node_modules/hyperformula/es/index.mjs
@ ./src/index.js
I found out that webpack 4 does not support exports, and there seems to be no easy workaround for that. By tweaking the webpack configuration, I managed to make the project import HyperFormula correctly using the legacy paths. Working demo. |
I have retested all the demos available on https://github.com/handsontable/hyperformula-demos/tree/import-demos plus the bundlers mentioned by @budnix getting the same results. On top of the above I have tested:
|
TODO: verify it with the code example in issue #1143 |
It works correctly. The issue you reported was caused by running the setup code twice. I created a demo for svelte: https://github.com/handsontable/hyperformula-demos/tree/import-demos/import-demo-esm-svelte Angular case is still to be verified. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #1377 +/- ##
========================================
Coverage 97.36% 97.36%
========================================
Files 169 169
Lines 14421 14421
Branches 3021 3021
========================================
Hits 14041 14041
Misses 380 380 |
Angular issue can be resolved by setting Unfortunately, I couldn't make combination Angular + Typescript 4 work. I'm afraid we need to ask our clients to upgrade to Typescript 5 if they want to use HyperFormula 3.x with Angular. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👌
I have retested the previously mentioned configurations and performed the migration steps - found out that the |
Context
.mjs
extensions and adjust the import and export statements in the output (custom babel plugin)exports
property topackage.json
that lists all valid ways of importing HyperFormulaUseful reading about similar solutions:
.ts
microsoft/TypeScript#49462.mjs
output microsoft/TypeScript#18442Related issues:
Fixes #1344
New import paths for the language files
Breaking change for projects that use Typescript, Angular <=17, or Webpack <=4
Angular
moduleResolution
moduleResolution
moduleResolution
moduleResolution
moduleResolution
moduleResolution
Typescript
moduleResolution
moduleResolution
moduleResolution
moduleResolution
Webpack
resolver-default
resolver-default
Webpack 4 has 2 separate issues:
mjs
files.exports
property topackage.json
.For the former issue, there is a workaround. It's enough to configure a rule for
mjs
files. But it seems that there is no way to make it understand theexports
property. For that reason, Webpack 4 can work with HyperFormula 3.0.0, but only with import paths that match the actual paths (ignoring theexports
property that provides the artificial paths).Further reading:
Parcel
resolver-default
Further reading:
package.json#exports
map parcel-bundler/parcel#4155Testing
Test importing HF in various setups
moduleResolution
moduleResolution
moduleResolution
moduleResolution
moduleResolution
resolver-default
Demo projects are available in the hyperformula-demos repo.
Tested by @budnix:
Tested by @magierg
Further verification
Types of changes
Checklist: