Skip to content

Commit

Permalink
fix: change to output as ES modules (#365)
Browse files Browse the repository at this point in the history
This library is broken since v6.0.1 after PR #356. Users face this stack trace:

```
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/philip_mcmahon/code/editions/projects/aws/node_modules/read-pkg-up/index.js
require() of ES modules is not supported.
require() of /Users/philip_mcmahon/code/editions/projects/aws/node_modules/read-pkg-up/index.js from /Users/philip_mcmahon/code/editions/projects/aws/node_modules/@guardian/cdk/lib/constants/library-info.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/philip_mcmahon/code/editions/projects/aws/node_modules/read-pkg-up/package.json.
```

This change updates tsconfig to output as ES modules rather than commonjs. This slightly goes against the recommendations (https://github.com/guardian/recommendations/blob/master/npm-packages.md#compiling), however as the library only gets used in controlled environments, this should be fine.
  • Loading branch information
akash1810 authored Mar 30, 2021
1 parent b16900f commit b4ad69d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"module": "ES2020",
"moduleResolution": "node",
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"strict": true,
"noUnusedLocals": true,
Expand All @@ -14,7 +15,7 @@
"inlineSources": true,
"experimentalDecorators": true,
"typeRoots": ["./node_modules/@types"],
"outDir": "lib",
"outDir": "lib"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "test", "src/**/*.test.ts", "src/**/__snapshots__/**", "src/**/__mocks__/**"]
Expand Down

0 comments on commit b4ad69d

Please sign in to comment.