Can't update ESM-only @graasp/translations package
- Dominant language
- TypeScript
- Stars
- 7
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
The `@graasp/translations` package is configured to export an ESM only build created with `tsc`.
The backend currently compiles down to CJS, so it is not possible to use newer version of the translations package.
There are multiple solutions to this.
### Solution 1: Convert the backend to use ESM
This is the most "future-proof" solution but also the most time-consuming and un-certain.
Having tried to do it quite un-successfully in #1117 the following issues have surfaced:
- Need to use fully-qualified paths in imports -> this is easily handled by a code-mod and the small number of manual fixes is OK.
- the tests need to be able to run on the ESM source, but Jest (our current testing framework) has ESM support under the experimental frag since at least 4 years, and trying to make tests work with the migrated ESM source code proved unsuccessful.
- We could use a different testing framework, like `vitest` which support ESM natively, but the size/number of tests to refactor is quite high. A more progressive transition to vitest is preferable.
### Solution 2: What if the issue is not the backend but actually `@graasp/translations`
While trying out Solution 1 and it miserably failing after 2 days. The question arrose whether we could maybe make it so that translations could be used inside a commonJS project.
The main blocker for this was:
- since translations was using the `module=nodenext` config, the json file imports had to be asserted with the new `with { type: 'json' }` syntax
- this new syntax is not convertible as is in commonJS when using default tsc compilation to `module=commonJS`...
So we are done ? no solution ?
No. We can use a :star: bundler ✨ !
And indded, it worked, using a bundler allows us to produce a commonJS package that conforms to the requirements of the backend.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.