hyperformula icon indicating copy to clipboard operation
hyperformula copied to clipboard

Language files do not work with ES modules in node

Open sequba opened this issue 2 years ago • 1 comments

Description

Importing language files:

  • seems to work in UMD module system
  • seems to work in CommonJS although we should verify if the setup is optimal
  • does not work in ESM in node
  • does not work in ESM in React

Demo

https://codesandbox.io/p/devbox/test-hyperformula-with-nodejs-pgkwd8

Error messages

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/workspaces/sandbox/node_modules/hyperformula/es/i18n/languages/frFR' imported from /workspaces/sandbox/index.js
Did you mean to import hyperformula/es/i18n/languages/frFR.js?
(node:328) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/workspaces/sandbox/node_modules/hyperformula/es/i18n/languages/frFR.js:417
export default dictionary;
^^^^^^

SyntaxError: Unexpected token 'export'

Notes

  • Originally reported by @guenlm in https://github.com/handsontable/hyperformula/discussions/1340
  • Consulted with @budnix in https://handsoncode.slack.com/archives/D0300KBP0H2/p1701186053349819 (internal discussion)
  • The fix might require a breaking change.

Related issues

  • https://github.com/handsontable/hyperformula/issues/1143
  • https://github.com/handsontable/hyperformula/issues/1144

sequba avatar Nov 28 '23 17:11 sequba

Relevant discussion:

  • https://github.com/microsoft/TypeScript/issues/18442
  • https://github.com/microsoft/TypeScript/issues/49462
  • https://www.sensedeep.com/blog/posts/2021/how-to-create-single-source-npm-module.html

sequba avatar Feb 14 '24 11:02 sequba