Skip to content

Fix migrations & schematics commonjs type for latest package, adjust module output#17183

Merged
damyanpetev merged 2 commits intomasterfrom
sstoychev/fix-migrations-ng21
Apr 16, 2026
Merged

Fix migrations & schematics commonjs type for latest package, adjust module output#17183
damyanpetev merged 2 commits intomasterfrom
sstoychev/fix-migrations-ng21

Conversation

@ChronosSF
Copy link
Copy Markdown
Member

@ChronosSF ChronosSF commented Apr 15, 2026

Closes #

Additional information (check all that apply):

  • Bug fix
  • New functionality
  • Documentation
  • Demos
  • CI/CD

Fix: ng update migrations crash with "type": "module"

The latest ng-packagr@21.2.2 sets "type": "module" in the published package.json, causing Node.js to treat all .js files as ES modules.

[error] ReferenceError: exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and 'igniteui-angular-samples\node_modules\igniteui-angular\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at igniteui-angular-samples/node_modules/igniteui-angular/migrations/common/import-helper.js:2:23
    [...]

The migrations and schematics are CommonJS so their exports = ... syntax throws exports is not defined in ES module scope. The fix adds a { "type": "commonjs" } package.json to both the migrations/ and schematics/ source directories, overriding the parent ESM setting for those subdirectories. These files are automatically copied to dist by the existing gulp tasks.
Additionally, the specific import-helper.js is a pre-compiled file to avoid a TypeScript emit converting dynamic imports to require, which is no longer needed with more modern module output modes so that is removed and updated.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses ng update migration/schematics crashes when the published igniteui-angular package is treated as ESM ("type": "module"), by ensuring the migrations/ and schematics/ subdirectories are explicitly treated as CommonJS at runtime.

Changes:

  • Add projects/igniteui-angular/schematics/package.json with { "type": "commonjs" }.
  • Add projects/igniteui-angular/migrations/package.json with { "type": "commonjs" }.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
projects/igniteui-angular/schematics/package.json Adds a nested package boundary to force CommonJS semantics for schematics runtime loading.
projects/igniteui-angular/migrations/package.json Adds a nested package boundary to force CommonJS semantics for migrations runtime loading.

Comment thread projects/igniteui-angular/migrations/package.json
Comment thread projects/igniteui-angular/schematics/package.json
@ChronosSF
Copy link
Copy Markdown
Member Author

@copilot apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 15, 2026

@copilot apply changes based on the comments in this thread

Applied. I updated /projects/igniteui-angular/.npmignore to keep migrations/package.json and schematics/package.json in the published package (!migrations/package.json, !schematics/package.json). Verified with npm pack --dry-run that both files are now included. Commit: 51d6bbe.

Comment thread projects/igniteui-angular/.npmignore
damyanpetev
damyanpetev previously approved these changes Apr 15, 2026
@damyanpetev damyanpetev force-pushed the sstoychev/fix-migrations-ng21 branch from 51d6bbe to 454d4e6 Compare April 16, 2026 11:24
ChronosSF and others added 2 commits April 16, 2026 15:55
@damyanpetev damyanpetev force-pushed the sstoychev/fix-migrations-ng21 branch from 84a0109 to 69dda0b Compare April 16, 2026 12:55
@damyanpetev damyanpetev changed the title fix(migrations): adding correct type for migrations and schematics for latest CLI Fix migrations & schematics commonjs type for latest package, adjust module output Apr 16, 2026
@damyanpetev damyanpetev merged commit 024b8e8 into master Apr 16, 2026
6 checks passed
@damyanpetev damyanpetev deleted the sstoychev/fix-migrations-ng21 branch April 16, 2026 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants