-
-
Notifications
You must be signed in to change notification settings - Fork 228
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
Separate grapher and the OWID site into separate standalone projects in the same repo #1157
Comments
some justification on why there's no visible progress at all: What did I do?I decided it would be a good first step to convert our codebase to fully using ES modules, and thought that this would be an easy and sensible first step. It was not. What are ES modules?There are a number of different formats in which JS modules can be published. For a long time, CommonJS (CJS) modules were the norm since they were the only format recognized by Node. But along came ES Modules (ESM for short), a standard that works in both the browser and in Node. It is natively supported in Node 12.20+. It was meant to instantaneously fix all the weirdnesses the JS packaging has. ESM uses the In our case, since our code is written in TypeScript, we are already using the ESM syntax, but The Upside: Why ES modules are greatIn principle, ES modules are great. They will, at some point (it's still JavaScript), be perfectly supported by all browsers and tools. Their syntax is more sensible (mostly). It allows for parallel download of sources at parse-time. Tools like Webpack can do way better tree-shaking with ESM sources. Additionally, many packages are now published as ESM-only. One very relevant example is the latest version of d3. We can only upgrade to that version if we ourselves upgrade to ESM. The Downside: Why ES modules are terribleWell, it's not necessarily the ESM design that is to blame. It's the compatibility and tooling around it. You see, you can never import an ESM module from CommonJS code, but it's perfectly possible to import CommonJS from ESM code. And since the whole world didn't switch over to ESM in one day, and a lot of our In fact, many modules are published as dual modules: They contain both an ESM and a CJS entry point, and specify these in Consider a simple import Select from "react-select"
const render = () => <Select /> This will work fine if react-select is imported as an ESM module, but it won't if react-select is CJS. In that case, you would have to write The only alternatives I could come up with are:
See for yourselfIf you're brave, you can take a look at the shipwreck itself, at https://github.com/owid/owid-grapher/tree/webpack5-esm. There is an immense number of fixup commits in there. Many things work, some are extremely hacky, some don't work at all. For example, the SVG tester doesn't work and is hard to fix since it uses the |
Progress report: I rebased https://github.com/owid/owid-grapher/tree/webpack5-esm to the latest master. diff --git a/devTools/tsconfigs/tsconfig.base.json b/devTools/tsconfigs/tsconfig.base.json
--- a/devTools/tsconfigs/tsconfig.base.json
+++ b/devTools/tsconfigs/tsconfig.base.json
@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
- "module": "commonjs",
+ "module": "es2020",
"strict": true, What it does is to instruct TS to output ESM code (rather than CommonJS) in the
|
In other good news, the deploy was successful and the branch is now live on tufte. |
Also related: |
Closing this issue, since the previous approach hit a dead end with ESM. Superseded by #1667 |
Tasks
settings
module?ts-loader
packages/
foldergrapher
module into its own packagets-node
-based setupWhy
Risks
The text was updated successfully, but these errors were encountered: