ngx-translate-extract icon indicating copy to clipboard operation
ngx-translate-extract copied to clipboard

Angular 13 issue

Open tarlepp opened this issue 3 years ago • 51 comments

After I upgraded Angular from 12 to 13 I got following error:

yarn run v1.22.15
$ ngx-translate-extract --input ./src --output ./src/assets/i18n/*.json --clean --format-indentation '  ' --sort --format namespaced-json --null-as-default-value && for files in src/assets/i18n/*.json; do echo >> $files; done;
node:internal/modules/cjs/loader:979
    throw new ERR_REQUIRE_ESM(filename, true);
    ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /app/node_modules/@angular/compiler/fesm2015/compiler.mjs not supported.
Instead change the require of /app/node_modules/@angular/compiler/fesm2015/compiler.mjs to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/app/node_modules/@biesbjerg/ngx-translate-extract/dist/parsers/pipe.parser.js:3:20)
    at Object.<anonymous> (/app/node_modules/@biesbjerg/ngx-translate-extract/dist/cli/cli.js:6:23)
    at Object.<anonymous> (/app/node_modules/@biesbjerg/ngx-translate-extract/bin/cli.js:3:1) {
  code: 'ERR_REQUIRE_ESM'
}
error Command failed with exit code 1.

Any idea how to fix this?

tarlepp avatar Nov 05 '21 15:11 tarlepp

Hello @biesbjerg, Can you fix this issue ? Thanks :)

damien-skyboy avatar Nov 10 '21 12:11 damien-skyboy

I tried to do something like this but error is still present :

async function loadCompiler() {
  compiler_1 = await import('@angular/compiler');
};
loadCompiler();

damien-skyboy avatar Nov 10 '21 12:11 damien-skyboy

I have found a temporary workaround:

install @angular/[email protected] as dev dependency under an alias in your project package.json

"devDependencies": {
    ...
    "@angular/compiler12": "npm:@angular/[email protected]"
}

change the require statement to your alias package name in directive.parser.js and pipe.parser.js files:

const compiler_1 = require("@angular/compiler12");

sbinkert avatar Nov 10 '21 21:11 sbinkert

I have found a temporary workaround:

install @angular/[email protected] as dev dependency under an alias in your project package.json

"devDependencies": {
    ...
    "@angular/compiler12": "npm:@angular/[email protected]"
}

change the require statement to your alias package name in directive.parser.js and pipe.parser.js files:

const compiler_1 = require("@angular/compiler12");

This works well, thanks! Hopefully we'll see an official fix soon

dimitrov-d avatar Nov 11 '21 09:11 dimitrov-d

So currently there are multiple PR's to fix this one; #247, #248 and #249 - just reporting all those here for now.

tarlepp avatar Nov 15 '21 21:11 tarlepp

@biesbjerg could you take a look of those PR's ?

tarlepp avatar Nov 23 '21 17:11 tarlepp

Thanks to @venraij @tiberiuzuld @bartholomej we have a new version for Angular 13. I am using it in production already.

Pull request and branch

Hope you'll check it out soon ;) @biesbjerg


For those who want to use it today... Temporarily, you can install as follows:

npm i @bartholomej/ngx-translate-extract --save-dev

bartholomej avatar Nov 26 '21 17:11 bartholomej

@bartholomej @tarlepp @venraij

Looks like this issue doesn't occur anymore with Angular 13.0.3.

Tohnmeister avatar Dec 03 '21 14:12 Tohnmeister

@bartholomej @tarlepp @venraij

Looks like this issue doesn't occur anymore with Angular 13.0.3.

Oh, I need to test with that version, thanks for the info! I'll rerport the results here after I have done that, most likely late saturday or sunday.

tarlepp avatar Dec 03 '21 14:12 tarlepp

@Tohnmeister Updated Angular to 13.0.3 version and I'm still getting exactly same error.

tarlepp avatar Dec 04 '21 16:12 tarlepp

@tarlepp Did you try this version? v8.0.1

npm i @bartholomej/ngx-translate-extract --save-dev

bartholomej avatar Dec 04 '21 17:12 bartholomej

@tarlepp Did you try this version? v8.0.1

npm i @bartholomej/ngx-translate-extract --save-dev

Yep with that it works just fine, I already commented that on that PR https://github.com/biesbjerg/ngx-translate-extract/pull/247#issuecomment-980078848

But as like @Tohnmeister said https://github.com/biesbjerg/ngx-translate-extract/issues/246#issuecomment-985560773:

@bartholomej @tarlepp @venraij Looks like this issue doesn't occur anymore with Angular 13.0.3.

I cannot confirm that this original library works as expected with Angular 13.0.3 version

tarlepp avatar Dec 04 '21 18:12 tarlepp

@Tohnmeister could you provide some example repository where this repository is working with Angular 13.0.3 like you said earlier?

tarlepp avatar Dec 05 '21 21:12 tarlepp

The repository we're using this is in, is not open source unfortunately. I can provide you the exact version numbers though.

@angular/cli: 13.0.4
@angular/compiler: 13.0.3
@angular/compiler-cli: 13.0.3
@angular/core: 13.0.3
@biesbjerg/ngx-translate-extract: 4.2.0
@biesbjerg/ngx-translate-extract-marker: 1.0.0
@ngx-translate/core: 11.0.1

And we have this as a script in our package.json:

"extract-i18n": "ngx-translate-extract --input ./src --output ../locale/myclient.pot --clean --sort --format pot --marker marker",

We're using quite an old version of ngx-translate-extract. But this version had the issue described in this topic, after upgrading to Angular 13.0.1 initially. It doesn't have the issue anymore after upgrading to 13.0.3. Verified by rolling back the Angular upgrade, and setting the version back to 13.0.1. Then the issue occurred again. Re-upgraded to 13.0.3 and the issue dissappeared.

Hope this helps.

Tohnmeister avatar Dec 06 '21 14:12 Tohnmeister

@Tohnmeister Yes, I can confirm that this very old version 4.2.0 starts to extract but crashes on a few other bugs. For example: 'Parser Error: Missing expected : at column 21 in [headerTemplate; context: { data, me }]

Stable version of ngx-translate-extract doesn't work at all with Angular 13.0.3

You're using two years old version and 3 major versions have been released in the meantime, so it's just a coincidence that it works in this particular combination :)

For me, the solution is to release this new version (v8), which drops support for old versions of Angular.

What do you think?

bartholomej avatar Dec 06 '21 18:12 bartholomej

I agree that the solution is to release a proper up-to-date version that supports Angular 13. Although I'd prefer having it merged in @biesbjerg's repository. What are your thoughts on LTS, etc.?

Tohnmeister avatar Dec 07 '21 07:12 Tohnmeister

I use latest Angular version and this bug is still present:

@angular/cli: 13.0.4
@angular/compiler: 13.0.3
@angular/compiler-cli: 13.0.3
@angular/core: 13.0.3
@biesbjerg/ngx-translate-extract: 7.0.4
@ngx-translate/core: 14.0.0

usarskyy avatar Dec 09 '21 07:12 usarskyy

@usarskyy Try the last Angular version (v13.1.0) with ngx-translate-extract 4.2.0. It works for me.

milanopetrovic avatar Dec 10 '21 07:12 milanopetrovic

@usarskyy Try the last Angular version (v13.1.0) with ngx-translate-extract 4.2.0. It works for me.

You're using old version of ngx-translate-extract, see - https://github.com/biesbjerg/ngx-translate-extract/issues/246#issuecomment-987053134

I just updated Angular to 13.1.0 and the problem still exists.

tarlepp avatar Dec 10 '21 08:12 tarlepp

@tarlepp If your comment was for me, where to find the newest version ? Accordingly to NPM and Github I am using latest version: image image

usarskyy avatar Dec 10 '21 08:12 usarskyy

@usarskyy I tried with Angular 13.1.0 and ngx-translate-extract version 7.0.4 and the same issue still exists. And that was for @milanopetrovic

tarlepp avatar Dec 10 '21 09:12 tarlepp

Hey i using angular-cli version 13.1.1 and i present the same problem @angular/cli: 13.1.1 @angular/compiler: ~13.0.0 @angular/compiler-cli: ~13.0.0 @angular/core: ~13.0.0

alejophotoart avatar Dec 20 '21 22:12 alejophotoart

@usarskyy @alejophotoart Yes, we're still waiting for @biesbjerg to take a look at it :(

Meanhwhile you can use fork which works with Angular 13.

See this https://github.com/biesbjerg/ngx-translate-extract/issues/246#issuecomment-980180791

bartholomej avatar Dec 21 '21 12:12 bartholomej

@bartholomej The fork doesn't work for me. It fails with An error occurred: TypeError: mkdirp.sync is not a function when saving to the file.

The issue seems to be this line https://github.com/bartholomej/ngx-translate-extract/blob/ng13/src/cli/tasks/extract.task.ts#L141

The imported mkdirp package is an object that contains the default property and inside there the sync function.

Can we fix that somehow until the official library is ready for Angular 13?

Thanks in advance!

orestisioakeimidis avatar Jan 12 '22 08:01 orestisioakeimidis

@orestisioakeimidis You're right! And here is the fix https://github.com/biesbjerg/ngx-translate-extract/pull/247#issuecomment-1011350636 ;)

bartholomej avatar Jan 12 '22 18:01 bartholomej

@bartholomej I know that the following is not related to this thread, but what do you think of incorporating this PR https://github.com/biesbjerg/ngx-translate-extract/pull/181 in you fork? It'd be great to support some kind of context in the source strings. Thanks in advance!

orestisioakeimidis avatar Feb 07 '22 11:02 orestisioakeimidis

I'm using version 7.0.4 and Angular 13.2.0 and the issue still reproduces.

sergiubologa avatar Feb 10 '22 04:02 sergiubologa

Hey guys, is there any chance that the PR fixing the Angular 13 issues will be merged any time soon? We are choosing new translate library for our project, this one is great and only problem is, that its not working for Angular 13. Should we do our own fork (or use this one - https://github.com/biesbjerg/ngx-translate-extract/issues/246#issuecomment-980180791), or is there a chance that this will be merged soon?

Pirozek avatar Feb 22 '22 14:02 Pirozek

I think that we're all just waiting some feedback from @biesbjerg

tarlepp avatar Feb 22 '22 17:02 tarlepp

Hi @biesbjerg, I've been sponsoring you (via the @vendure-ecommerce org) for your great work on this library since Sept 2021. I just ran into this issue and I'm concerned about its resolution. As a long-time OSS maintainer, I'm familiar with the pressures and time constraints that can make it hard to keep up with a popular library.

If you simply have to time/ability/desire to maintain this lib, this is completely your prerogative and I certainly would understand and respect your situation. I think just some clarification on the status of this issue/this lib would go a long way in terms of giving all of us some idea of what to do next.

@bartholomej thank you for your efforts to update this 👍

michaelbromley avatar Mar 03 '22 10:03 michaelbromley