Nativescript-cli: NPM Plugins not working in Preview

Created on 8 Apr 2019  路  2Comments  路  Source: NativeScript/nativescript-cli

Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

  • CLI: 5.3.1
  • Cross-platform modules:
  • Android Runtime:
  • iOS Runtime:
  • Plugin(s):

Describe the bug
When I run my application using tns preview in my nativescript playground iOS app, with any third party node module include such as @ngx-translate/core, I get the error

Plugin @ngx-translate/core is not included in preview app on device 4F87D793-E6AE-4627-B24C-B84938B4FDBB and will not work.

@ngx-translate is not a nativescript plugin, instead it is just a Angular Module.

To Reproduce

Expected behavior

Sample project

Additional context

question

Most helpful comment

@mohammedzamakhan,

NativeScript Preview app is prebuilt with specified set of plugins. In other words, you can use only the prebuilt set of plugins regardless if the plugin is NativeScript plugin or not. This is by design and is fully expected behavior.

If @ngx-translate/core consists only from JavaScript code (without native code), you can use tns preview --bundle. Webpack will traverse your source code, collect all required dependencies and output them in bundle.js which will be transferred on device. So your plugin's code will be available runtime.

All 2 comments

@mohammedzamakhan,

NativeScript Preview app is prebuilt with specified set of plugins. In other words, you can use only the prebuilt set of plugins regardless if the plugin is NativeScript plugin or not. This is by design and is fully expected behavior.

If @ngx-translate/core consists only from JavaScript code (without native code), you can use tns preview --bundle. Webpack will traverse your source code, collect all required dependencies and output them in bundle.js which will be transferred on device. So your plugin's code will be available runtime.

im using --bundle but it result:
LOG from device Mrjs: },
LOG from device Mrjs: "status": 404,
LOG from device Mrjs: "statusText": "ERROR",
LOG from device Mrjs: "lazyUpdate": null,
LOG from device Mrjs: "headers": {
LOG from device Mrjs: "normalizedNames": {},
LOG from device Mrjs: "url": "/data/data/org.nativescript.preview/files/app/assets/i18n/en.json",
LOG from device Mrjs: "ok": false,
LOG from device Mrjs: "name": "HttpErrorResponse",
LOG from device Mrjs: "message": "Http failure response for /data/data/org.nativescript.preview/files/app/assets/i18n/en.json: 404 ERROR",

Was this page helpful?
0 / 5 - 0 ratings