Skip to content
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

fix: change to output as ES modules #365

Merged
merged 1 commit into from
Mar 30, 2021
Merged

fix: change to output as ES modules #365

merged 1 commit into from
Mar 30, 2021

Conversation

akash1810
Copy link
Member

What does this change?

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.

Does this change require changes to existing projects or CDK CLI?

No.

How to test

  • Checkout the branch
  • npm link the project
  • Update an existing project to use the linked version of @guardian/cdk
  • Synth a stack
  • Observe no errors

How can we measure success?

The library can be used again!

Have we considered potential risks?

n/a

@akash1810 akash1810 requested a review from a team March 30, 2021 12:34
@akash1810 akash1810 changed the title fix: change to output as es modules fix: change to output as ES modules Mar 30, 2021
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.
Copy link
Contributor

@philmcmahon philmcmahon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@akash1810 akash1810 merged commit b4ad69d into main Mar 30, 2021
@akash1810 akash1810 deleted the aa-tsconfig branch March 30, 2021 12:40
@github-actions
Copy link
Contributor

🎉 This PR is included in version 6.2.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

akash1810 added a commit that referenced this pull request Mar 30, 2021
akash1810 added a commit that referenced this pull request Mar 31, 2021
akash1810 added a commit that referenced this pull request Mar 31, 2021
akash1810 added a commit that referenced this pull request Mar 31, 2021
akash1810 added a commit that referenced this pull request Mar 31, 2021
akash1810 added a commit that referenced this pull request Mar 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants