jsverse / transloco

🚀 😍 The internationalization (i18n) library for Angular
https://jsverse.github.io/transloco/
MIT License
2.03k stars 196 forks source link

[Bug]: ng add throws error: Cannot read property 'forEach' of undefined #22

Closed omarAjmi closed 5 years ago

omarAjmi commented 5 years ago

I'm submitting a...


[x ] Bug report

Current behavior

simple installation process with ng add throws exception Cannot read property 'forEach' of undefined after choosing fr, en, ar as for locales. choosing webpack as loader. choosing jsonas file type. chhosing default files directory /src/asstests/i18n i tried creating the folder i18nunder src/asstets before hand but still the error persists.

Expected behavior

installation finishes as expected.

What is the motivation / use case for changing the behavior?

i am following your installation guidelines and steps.

Environment


Angular version: 8
OS:Wind 10
editor VSCode
itayod commented 5 years ago

Hi @omarAjmi did you separated the locales by comma?

omarAjmi commented 5 years ago

yes literaly like this fr, en, ar : with spaces and commas edit[2]: i even tried it without the spaces, but same error. edit[3]: i managed to make the translation work only by executing the installer tasks manualy as described in the README.md, the installer allways throws the same error.

shaharkazaz commented 5 years ago

@omarAjmi I have just tried to reproduce as well but all worked as expected 🤔 WhatsApp Image 2019-08-19 at 8 18 12 AM

itayod commented 5 years ago

Hi, I have tried to reproduce it on several platforms and it worked perfectly. Could you please send us a link to your repository with a reproduction

nartc commented 5 years ago

I just ran into the same issue image

This is a work project so I can't really share a link to this repo. I've tested it on a new cli project and it worked perfectly.

Angular CLI version: 8.2.2 Angular: 8.2.2

I can provide more information about the environment if needed.

omarAjmi commented 5 years ago

@nartc i ran into the same problem on my workstation, also on win10, we can share our package.json, iguess it's a dependency problem, maybe they get a hint or something from it. here is mine:

{ "name": "agence-vol", "version": "0.0.0", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e" }, "private": true, "dependencies": { "@angular/animations": "~8.0.1", "@angular/cdk": "^8.0.1", "@angular/common": "~8.0.1", "@angular/compiler": "~8.0.1", "@angular/core": "~8.0.1", "@angular/forms": "~8.0.1", "@angular/material": "^8.0.1", "@angular/platform-browser": "~8.0.1", "@angular/platform-browser-dynamic": "~8.0.1", "@angular/router": "~8.0.1", "@ng-bootstrap/ng-bootstrap": "4.2.1", "@ngneat/transloco": "^1.1.1", "angular-font-awesome": "^3.1.2", "angular-translate": "^2.18.1", "bootstrap": "4.1.1", "flag-icon-css": "^3.3.0", "font-awesome": "^4.7.0", "moment": "^2.24.0", "ng5-slider": "^1.2.4", "ngx-bootstrap": "^5.0.0", "ngx-flag-icon-css": "^1.0.1", "pretty-checkbox": "^3.0.3", "rxjs": "~6.4.0", "tslib": "^1.9.0", "zone.js": "~0.9.1" }, "devDependencies": { "@angular-devkit/build-angular": "~0.800.0", "@angular/cli": "~8.0.4", "@angular/compiler-cli": "~8.0.1", "@angular/language-service": "~8.0.1", "@types/node": "~8.9.4", "@types/jasmine": "~3.3.8", "@types/jasminewd2": "~2.0.3", "codelyzer": "^5.0.0", "jasmine-core": "~3.4.0", "jasmine-spec-reporter": "~4.2.1", "karma": "~4.1.0", "karma-chrome-launcher": "~2.2.0", "karma-coverage-istanbul-reporter": "~2.0.1", "karma-jasmine": "~2.0.1", "karma-jasmine-html-reporter": "^1.4.0", "protractor": "~5.4.0", "ts-node": "~7.0.0", "tslint": "~5.15.0", "typescript": "~3.4.3" } }

omarAjmi commented 5 years ago

@nartc for the time being, you can reproduce the installation process manually by fallowing this https://github.com/ngneat/transloco#installation it worked for me, it's unfortunately though, this is a nice tool

omarAjmi commented 5 years ago

not a dependencies problem, i've tried it on a brand new project, it worked, then i copied the old project dependencies then ran npm install then ran the ng add @ngneat/transloco, it worked fine, humm 🤔

NetanelBasal commented 5 years ago

@omarAjmi try to delete your node_modules and clear the cache, please.

inorganik commented 5 years ago

I was able to run the schematic on an existing project no problem, however, running ng new and creating a new app, I ran into this error.

Using Angular CLI: 7.3.9

@NetanelBasal I tried blowing away node_modules and reinstalling, also, I ran npm i @ngneat/transloco before running the schematic.

Nothing worked. I even debugged the schematic, the only 'forEach' I could find is in the createTranslateFiles function, which is getting the langs.

NetanelBasal commented 5 years ago

@inorganik I tried npx @angular/cli@7.3.9 new projectName, and it worked. Can you upload the tested project to Github, please?

inorganik commented 5 years ago

Sure, here you go: https://github.com/inorganik/i18n-demo

Thanks for the quick responses!

FWIW, my node version is v10.9.0

NetanelBasal commented 5 years ago

@inorganik thanks! We reproduce it with your repo. @itayod will check it out.

itayod commented 5 years ago

@inorganik Thanks for the example, I will check it out later today :)

itayod commented 5 years ago

@inorganik, @omarAjmi the following PR should fix this problem. Thanks again for letting us know 🙏

omarAjmi commented 5 years ago

@itayod can you elaborate on what was the problem? please

itayod commented 5 years ago

sure, the problem was in cases of "import * as... " or "import defaultVar from..." on app.module.ts file. in those cases, one of the ast functions that should add import names to this was failing.

omarAjmi commented 5 years ago

Much appreciated 🙏🙏🙏

krokofant commented 4 years ago

The lines I had to remove was related to:

import sv from '@angular/common/locales/sv';

Then it started to work :-)