Skip to content

fix(@angular/cli): error if Angular compiler is used in a schematic#24662

Merged
angular-robot[bot] merged 1 commit intoangular:mainfrom
crisbeto:text-encoder-error
Feb 7, 2023
Merged

fix(@angular/cli): error if Angular compiler is used in a schematic#24662
angular-robot[bot] merged 1 commit intoangular:mainfrom
crisbeto:text-encoder-error

Conversation

@crisbeto
Copy link
Member

@crisbeto crisbeto commented Feb 5, 2023

When a schematic is executed, it is wrapped in a custom Node context. This context doesn't expose the same set of global variables as the default one. This can lead to an error if a schematic is importing the Angular compiler and the app is using i18n, because the TextEncoder isn't exposed through the custom context (see angular/angular#48940).

These changes add the TextEncoder to the context.

Fixes angular/angular#48940.

When a schematic is executed, it is wrapped in a custom Node context. This context doesn't expose the same set of global variables. This can lead to an error if a schematic is importing the Angular compiler and the app is using i18n, because the `TextEncoder` isn't exposed through the custom context (see angular/angular#48940).

These changes add the `TextEncoder` to the context.

Fixes angular/angular#48940.
@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Feb 5, 2023
import { parse as parseJson } from 'jsonc-parser';
import { createRequire } from 'module';
import { dirname, resolve } from 'path';
import { TextEncoder } from 'util';
Copy link
Member Author

Choose a reason for hiding this comment

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

I used an import for this, even though it's available globally, because for some reason the global variable wasn't in the typings.

@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Feb 6, 2023
@angular-robot angular-robot bot merged commit 234f265 into angular:main Feb 7, 2023
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Mar 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/cli target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ng g @angular/core:standalone throws when plural syntax is used in template (TextEncoder is not defined)

2 participants