Skip to content

fix: schematics fail with "exports is not defined in ES module scope" during ng update#585

Merged
timdeschryver merged 2 commits into
mainfrom
copilot/fix-ng-update-exception
Jun 5, 2026
Merged

fix: schematics fail with "exports is not defined in ES module scope" during ng update#585
timdeschryver merged 2 commits into
mainfrom
copilot/fix-ng-update-exception

Conversation

Copilot AI commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

ng-packagr sets "type": "module" in the distributed package.json, causing Node.js to treat all .js files in the package as ES modules. The schematics (used by ng update) are compiled as CommonJS and use exports/require, which breaks under that ESM context.

Changes

  • projects/testing-library/schematics/package.json — adds {"type": "commonjs"} to the schematics source directory

Node.js resolves module type from the nearest package.json, so this override scopes CommonJS treatment to the schematics/ subdirectory only. The file is picked up automatically by the existing ng-package.json assets glob ("schematics/**/*.json") and lands at dist/@testing-library/angular/schematics/package.json in the published package.

…onJS

The distributed package has "type": "module" (added by ng-packagr), which
causes Node.js to treat all .js files in the package as ES modules. The
schematics are compiled as CommonJS and use `exports`, so running ng-update
fails with "exports is not defined in ES module scope".

Adding a package.json with {"type": "commonjs"} in the schematics directory
tells Node.js to treat those .js files as CommonJS modules, fixing the error.
Copilot AI changed the title [WIP] Fix unhandled exception during ng update to Angular 22 fix: schematics fail with "exports is not defined in ES module scope" during ng update Jun 5, 2026
Copilot AI requested a review from timdeschryver June 5, 2026 16:06
@timdeschryver timdeschryver marked this pull request as ready for review June 5, 2026 16:40
@timdeschryver timdeschryver merged commit c05cec2 into main Jun 5, 2026
4 checks passed
@timdeschryver timdeschryver deleted the copilot/fix-ng-update-exception branch June 5, 2026 16:40
@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 19.4.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

ng update to 22 An unhandled exception occurred: exports is not defined in ES module scope

2 participants