tflori / angular-translator

translation module for angular
https://tflori.github.io/angular-translator/
MIT License
21 stars 6 forks source link

Error encountered resolving symbol values statically #7

Closed robie2011 closed 7 years ago

robie2011 commented 7 years ago

I have this strage error message, when I run npm start

ERROR in Error encountered resolving symbol values statically. Calling function 'TranslateConfig', function calls are not supported. Consider replacing the function or lambda
 with a reference to an exported function, resolving symbol AppModule 

Note: When I change a source file, then webpack will be recompiled successfully.

any ideas? node : v7.5.0 npm: 4.2.0 os: mac os 10.12.3

Full log

ash-3.2$ npm start

> nextlevel-client@0.0.0 start /Users/robert/repository/nextlevel17/nextlevel-client
> ng serve

As a forewarning, we are moving the CLI npm package to "@angular/cli" with the next release,
which will only support Node 6.9 and greater. This package will be officially deprecated
shortly after.

To disable this warning use "ng set --global warnings.packageDeprecation=false".

fallbackLoader option has been deprecated - replace with "fallback"
loader option has been deprecated - replace with "use"
fallbackLoader option has been deprecated - replace with "fallback"
loader option has been deprecated - replace with "use"
fallbackLoader option has been deprecated - replace with "fallback"
loader option has been deprecated - replace with "use"
fallbackLoader option has been deprecated - replace with "fallback"
loader option has been deprecated - replace with "use"
** NG Live Development Server is running on http://localhost:4200. **
Hash: f56ebb1d8cad504b0fcf
Time: 8390ms
chunk    {0} polyfills.bundle.js, polyfills.bundle.map (polyfills) 228 kB {4} [initial] [rendered]
chunk    {1} main.bundle.js, main.bundle.map (main) 4.59 kB {3} [initial] [rendered]
chunk    {2} styles.bundle.js, styles.bundle.map (styles) 10 kB {4} [initial] [rendered]
chunk    {3} vendor.bundle.js, vendor.bundle.map (vendor) 2.66 MB [initial] [rendered]
chunk    {4} inline.bundle.js, inline.bundle.map (inline) 0 bytes [entry] [rendered]

ERROR in Error encountered resolving symbol values statically. Calling function 'TranslateConfig', function calls are not supported. Consider replacing the function or lambda
 with a reference to an exported function, resolving symbol AppModule in /Users/robert/repository/nextlevel17/nextlevel-client/src/app/app.module.ts, resolving symbol AppModu
le in /Users/robert/repository/nextlevel17/nextlevel-client/src/app/app.module.ts
webpack: Failed to compile.
webpack: Compiling...
Hash: f56ebb1d8cad504b0fcf
Time: 1330ms
chunk    {0} polyfills.bundle.js, polyfills.bundle.map (polyfills) 228 kB {4} [initial]
chunk    {1} main.bundle.js, main.bundle.map (main) 4.59 kB {3} [initial]
chunk    {2} styles.bundle.js, styles.bundle.map (styles) 10 kB {4} [initial]
chunk    {3} vendor.bundle.js, vendor.bundle.map (vendor) 2.66 MB [initial]
chunk    {4} inline.bundle.js, inline.bundle.map (inline) 0 bytes [entry]
webpack: Compiled successfully.

package.json


{
  "name": "nextlevel-client",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "test": "ng test",
    "pree2e": "webdriver-manager update --standalone false --gecko false",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "^2.3.1",
    "@angular/compiler": "^2.3.1",
    "@angular/core": "^2.3.1",
    "@angular/forms": "^2.3.1",
    "@angular/http": "^2.3.1",
    "@angular/platform-browser": "^2.3.1",
    "@angular/platform-browser-dynamic": "^2.3.1",
    "@angular/router": "^3.3.1",
    "angular2-translator": "^1.3.0",
    "core-js": "^2.4.1",
    "rxjs": "^5.0.1",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.7.2"
  },
  "devDependencies": {
    "@angular/compiler-cli": "^2.3.1",
    "@types/jasmine": "2.5.38",
    "@types/node": "^6.0.42",
    "angular-cli": "1.0.0-beta.28.3",
    "codelyzer": "~2.0.0-beta.1",
    "jasmine-core": "2.5.2",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "protractor": "~4.0.13",
    "ts-node": "1.2.1",
    "tslint": "^4.3.0",
    "typescript": "~2.0.3"
  }
}

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

import { AppComponent } from './app.component';
// import { LanguageComponent } from './language.components';
import { TranslatorModule, TranslateConfig, TranslateService, TranslatePipe } from 'angular2-translator/angular2-translator';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    TranslatorModule
  ],

  providers: [
    {
        provide: TranslateConfig, useValue: new TranslateConfig({
        defaultLang: "de",
        providedLangs: ["de", "en"],
        detectLanguageOnStart: true
      })

    },

    TranslatePipe,
    TranslateService
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }
tflori commented 7 years ago

It seems angular team changed something in the @NgModule directive. I didn't tried this version yet.

I'm at work currently. Can you try to export the config and then use it?

config.ts

import { TranslateConfig } from 'angular2-translator/angular2-translator'

export const MyTranslateConfig = new TranslateConfig({...});

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

import { AppComponent } from './app.component';
// import { LanguageComponent } from './language.components';
import { TranslatorModule, TranslateConfig, TranslateService, TranslatePipe } from 'angular2-translator/angular2-translator';
import { MyTranslateConfig } from 'config';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    TranslatorModule
  ],

  providers: [
    { provide: TranslateConfig, useValue: MyTranslateConfig },

    TranslatePipe,
    TranslateService
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

WARNING: this is written in the editor and never compiled. Maybe I dont remember the syntax correctly. Please check the syntax :smile:

tflori commented 7 years ago

may be this file has to be changed as well: https://github.com/tflori/angular2-translator/blob/master/angular2-translator.ts

I can do this in the evening.

robie2011 commented 7 years ago

I removed alle providers from @NgModule and get this error

ERROR in Error encountered resolving symbol values statically. Calling function 'TranslateConfig', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol TranslatorModule in /Users/robert/repository/nextlevel17/nl2017-client/node_modules/angular2-translator/angular2-translator.ts, resolving symbol TranslatorModule in /Users/robert/repository/nextlevel17/nl2017-client/node_modules/angular2-translator/angular2-translator.ts

Maybe it would help to replace useValue: new with useFactory: () => new?

I'm not familiar with npm packages. I tried to change the source code in node_modules for testing purpose. But I'm getting this error:

ERROR in Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function (position 29:49 in the original .ts file), resolving symbol TranslatorModule in /Users/robert/repository/nextlevel17/nl2017-client/node_modules/angular2-translator/angular2-translator.ts
tflori commented 7 years ago

As I thought - this libray has the same way (create a new object inside providers: {} property from @NgModule) of providing the config. This seems not to work anymore. I will investigate in the evening.

tflori commented 7 years ago

Sorry, I can't reproduce it. I see you used angular-cli. So you also copied the code to your source folder right?

Maybe you can try download the source from this branch and try it with the code from there - may be it works. But anyway: I don't support angular-cli - especially because it is still beta

robie2011 commented 7 years ago

yes, I did.

I see. This must be an issue with angular-cli.

tflori commented 7 years ago

If this fix helps I can publish 1.3.1 from it - if not it would be nice if you find a solution and post it here. Thanks in advance!