EddyVerbruggen / nativescript-localize

Internationalization plugin for NativeScript using native capabilities of each platform
MIT License
79 stars 31 forks source link

NativeScript and Angular - Exception on preview #58

Closed sintecnos-lucabiffi closed 5 years ago

sintecnos-lucabiffi commented 5 years ago

I tried a very simple application starting from the standard template tns-template-drawer-navigation-ng and made no changes whatsoever. I then installed this plugin and imported it as shown in the tutorial. I created the "i18n" folder with 2 json (one is en.default.json) as shown in the tutorial. The import fails and returns the exception below.

Android platform Nativescript 5.0.3 Nativescript localize 4.0.1

Error calling module function

Error: com.tns.NativeScriptException: Failed to find module: "nativescript-localize/angular", relative to: app/tns_modules/
    com.tns.Module.resolvePathHelper(Module.java:146)
    com.tns.Module.resolvePath(Module.java:55)
    com.tns.Runtime.runModule(Native Method)
    com.tns.Runtime.runModule(Runtime.java:553)
    com.tns.Runtime.run(Runtime.java:545)
    com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:21)
    android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1025)
    android.app.ActivityThread.handleBindApplication(ActivityThread.java:5448)
    android.app.ActivityThread.-wrap2(ActivityThread.java)
    android.app.ActivityThread$H.handleMessage(ActivityThread.java:1564)
    android.os.Handler.dispatchMessage(Handler.java:102)
    android.os.Looper.loop(Looper.java:154)
    android.app.ActivityThread.main(ActivityThread.java:6186)
    java.lang.reflect.Method.invoke(Native Method)
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
File: "<unknown>, line: 1, column: 265

StackTrace:
        Frame: function:'require', file:'', line: 1, column: 266
        Frame: function:'', file:'file:///data/data/org.nativescript.preview/files/app/app/app.module.js', line: 4, column: 17
        Frame: function:'require', file:'', line: 1, column: 266
        Frame: function:'', file:'file:///data/data/org.nativescript.preview/files/app/main.js', line: 5, column: 20
        Frame: function:'require', file:'', line: 1, column: 266
ivayloc commented 5 years ago

@sintecnos-lucabiffi did you install the plugin as devDependency or just as dependency, it should be install as dependency ot at least I have installed it as dependency and it is working

sintecnos-lucabiffi commented 5 years ago

@ivayloc I just installed it with tns plugin add nativescript-localize from terminal

sintecnos-lucabiffi commented 5 years ago

Ok this happens on 3 different machines so I must be doing something really silly.

I tried with PCs with Windows7 and Windows10.

Steps to reproduce: I use VS Code + NativeScript extension and create a project with tns create my-project --template tns-template-blank-ng Add plugin with tns plugin add nativescript-localize

Add import { NativeScriptLocalizeModule } from "nativescript-localize/angular"; and NativeScriptLocalizeModule (in angular imports) into app.module.ts file

Run npm install just to be sure.

Set i18n folden under "app" folder, so the complete path would be C:\path_to_my_project\src\app\i18n

Then run tns preview and when I open the app the exception above described happens.

abhayastudios commented 5 years ago

@sintecnos-lucabiffi if I remember correctly, NativeScript preview doesn't support plugins? Does it work when you just run tns run android?

sintecnos-lucabiffi commented 5 years ago

@abhayastudios You're very right, if I build the project and install the APK at least I don't get any Exception when launching the app. Thank you!