Open eatyourgreens opened 1 year ago
Why our Mocha tests are using CommonJS to require modules, I do not know. Some Babel config rewriting import
as require
?
We could try adding regenerator-runtime/runtime
to the Mocha config.
https://stackoverflow.com/a/60522428
We could also try publishing the libraries as ES Modules, but need to be mindful of not breaking Zoo Notes or Mapping Viz.
Mocha Babel examples might be useful.
@zooniverse/classifier
and @zooniverse/react-components
, alongside the UMD modules built by webpack. Builds and deploys use the ES modules. Mocha tests require the UMD modules. Everything works but we need webpack builds, which are pretty big and slow, in order to run the tests.@zooniverse/async-states
, which is a single JS file, from CommonJS to ES6. Builds that use it run fine, but tests fail for both NextJS apps and the classifier, when they try to require
the ES module.Going to close https://github.com/zooniverse/front-end-monorepo/pull/3781 for now, but linking here because of relation to ESM
@zooniverse/panoptes-js
also uses require
and module.exports
(CommonJS.)
Shaun's ESM notes here are very useful.
next-i18next
breaks if you convert the config file to ES6.
There may be a workaround. See the conversation on that issue.
next-i18next
also breaks if you rename the config to next-i18next.config.cjs
.
Bun has a good explanation of Node module resolution and the differences between CommonJS and ESM.
Node 21 now has experimental support for require(esm)
.
https://joyeecheung.github.io/blog/2024/03/18/require-esm-in-node-js/
WHAT?? The tests for
app-project
andlib-classifier
are failing on:and
and etc
OK, so upon review:
Additional reading:
Status
🤷 throw_hands_up_emoji
Good gravy, I need to check with the other devs to see if anybody else has encountered the ESM import issues. I might have missed something someone on the team is already aware of, since this doesn't seem to be a niche problem.
Originally posted by @shaunanoordin in https://github.com/zooniverse/front-end-monorepo/issues/3361#issuecomment-1171274486