badges / shields

Concise, consistent, and legible badges in SVG and raster format
https://shields.io
Creative Commons Zero v1.0 Universal
23.71k stars 5.49k forks source link

Migrate frontend to ESM #6717

Open PyvesB opened 3 years ago

PyvesB commented 3 years ago

This is related to #6651, in particular https://github.com/badges/shields/pull/6651#discussion_r666389443.

Problem

Gatsby does not support ESM. See https://github.com/gatsbyjs/gatsby/issues/23705 and linked discussions for more information.

In particular, when running npm start midway through migrating the whole code to ESM, I was getting errors similar to the following:

[frontend] TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension "" for C:...\workspace\shields.cache\tmp-5248-0orlJ0tI72FY

npm run build was also producing different kinds of errors.

Current workaround

The solution was to break the frontend down into a separate module with its own frontend/package.json. Unlike Shields' top-level package.json, frontend/package.json does not contain the mention "type": "module", in other words it is still a CommonJS module.

In addition to mandating the extra frontend/package.json, the solution has the following caveats:

Future work

Once Gatsby becomes compatible with ESM, we would simply need to revert all aforementioned workarounds (apart from the require-hacker one), and potentially convert gatsby-browser.js, gatsby-config.js and gatsby-node.js to ESM formats as well. Additionally, it is my understanding that we will need to add js file extensions to the existing relative imports in the frontend code.

chris48s commented 1 year ago

This issue is kind of still relevant but has changed substantially.

Now that we are off of Gatsby, all the detail above has changed, but having migrated to Docusaurus, we do still have some CommonJS frontend code (but a lot less). See https://github.com/badges/shields/pull/9014#discussion_r1142330196

The relevant upstream issues are now: