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
Refactor researcher app to use ECMAScript modules (ESM) #496
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@sdevalk This is the first part of the ESM conversion. I have only updated the researcher app, but now I know what needs to be done, I can easily change the rest. I have NOT changed the |
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.
Nice work! I've added two questions.
# Conflicts: # package-lock.json
Renaming the config packages did give a problem. Cypress gave a weird error after renaming the package |
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.
Nice!
This pull request details the transition of the research app and dataset browser from CommonJS to ECMAScript Modules (ESM). The motivation behind this move is to align our projects with modern JavaScript standards, improve module interoperability, and prepare our codebase for future scalability and performance enhancements.
Next.js 13+ supports ESM simply by adding type:
module
to your package.json and renaming next.config.js → next.config.mjs.Step 1: Type
module
inpackage.json
Node.js allows JavaScript to be interpreted as an ES module via the package.json "type" field with a value of "module". Most config files are in CommonJS, so they need to be updated. If possible, I used
.ts
for config files. For others, alternative formats were chosen, as detailed below.next.config.mjs
, as.ts
is not supported yet (Next.js Pull Request #57656)..eslintrc.json
from.eslintrc.js
based on ESLint's documentation.postcss.config.json
frompostcss.config.js
, in line with Next.js PostCSS configuration guidelines.tailwind.config.ts
..cjs
format forjest.setup.js
andjest.config.js
.Step 2: Updating the typescript config
For Next.js, the recommended settings are
module: esnext
andmoduleResolution: bundler
:module: esnext
instructs TypeScript to output ESM syntax, similar to nodenext, but it's a more general setting that isn't tailored exclusively to Node.js. It's suitable for code running in various environments, including browsers and bundlers (like Webpack, which Next.js uses internally).moduleResolution: bundler
tells TypeScript that module resolution will be handled by a module bundler, which can apply additional transformations or optimizations to the modules beyond what Node.js's native ESM resolution does.These changes needed some minor updates:
src/i18n.ts
gave errors; I updated it based on the newest example code ofnext-intl
iso-639-1-dir
showed some typescript errors, I replaced it with the package it was forked from (and now updated)iso-639-1
.