From 1f298715d7a860690eec1b1324d07a8d8488d8d5 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Fri, 30 Jul 2021 13:07:52 -0400 Subject: [PATCH] Add "type":"module" to published root package.json file. The root package.json file was neglected in #8396, since it isn't generated in the same way as the other (nested) package.json files. This commit puts `"type": "module"` in the _published_ `@apollo/client/package.json` file, which is generated at build time as the file `dist/package.json`. The root `package.json` file that's checked into the repository does _not_ contain `"type": "module"` (even though putting it there would also put it in `dist/package.json`). Attempting to enable ES module syntax at that level interfered pretty severely with tools like ts-node, which we use to run various config/*.ts scripts. Rewriting those scripts is a job for another time. I'm happy to revisit this as the ecosystem progresses. --- config/prepareDist.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/config/prepareDist.js b/config/prepareDist.js index 5d35465337e..e58cd77c941 100644 --- a/config/prepareDist.js +++ b/config/prepareDist.js @@ -23,6 +23,12 @@ const distRoot = `${__dirname}/../dist`; const packageJson = require('../package.json'); const entryPoints = require('./entryPoints.js'); +// Enable default interpretation of .js files as ECMAScript modules. We don't +// put this in the source ../package.json file because it interferes with tools +// like ts-node, which we use to run various ../config/*.ts scripts. +// TODO(benjamn) Fully diagnose that interference. +packageJson.type = 'module'; + // The root package.json is marked as private to prevent publishing // from happening in the root of the project. This sets the package back to // public so it can be published from the "dist" directory.