nativescript-cli icon indicating copy to clipboard operation
nativescript-cli copied to clipboard

`tns plugin add` fails when tns-android key is missing in package.json of the app

Open NathanaelA opened this issue 8 years ago • 6 comments

Did you verify this is a real problem by searching

Yes, here.

Tell us about the problem

I do a lot of plugin development ;-) I tend to do tns plugin add ../src or tns plugin add pluginname-1.0.0.tgz All of these will cause nativescript to throw a error

TypeError: Cannot read property 'version' of undefined
    at PluginsService.getInstalledFrameworkVersion (/usr/local/lib/node_modules/nativescript/lib/services/plugins-service.js:261:29)
    at PluginsService.isPluginDataValidForPlatform (/usr/local/lib/node_modules/nativescript/lib/services/plugins-service.js:265:48)
    at PluginsService.<anonymous> (/usr/local/lib/node_modules/nativescript/lib/services/plugins-service.js:57:26)
    at next (native)
    at /usr/local/lib/node_modules/nativescript/lib/services/plugins-service.js:7:71
    at __awaiter (/usr/local/lib/node_modules/nativescript/lib/services/plugins-service.js:3:12)
    at action (/usr/local/lib/node_modules/nativescript/lib/services/plugins-service.js:56:83)
    at PluginsService.<anonymous> (/usr/local/lib/node_modules/nativescript/lib/services/plugins-service.js:253:27)
    at next (native)
    at /usr/local/lib/node_modules/nativescript/lib/services/plugins-service.js:7:71

The issue is inserted in the package.json: "nativescript-pluginname": "file:<path to dir>",

When you attempt to get version numbers, "file:....." doesn't match and causes the above error.

Which platform(s) does your issue occur on?

Both

Please provide the following version numbers that your issue occurs with:

At least since TNS 3.0, still happening in 3.2

Please tell us how to recreate the issue in as much detail as possible.

tns plugin add ../src from a demo folder

NathanaelA avatar Sep 14 '17 08:09 NathanaelA

This looks as duplicate of https://github.com/NativeScript/nativescript-cli/issues/3028 @NathanaelA can you please confirm you hit the issue only with npm5?

dtopuzov avatar Nov 08 '17 12:11 dtopuzov

No this occurs on NPM 3 also, in fact I don't know that I've seen this error since I moved to NPM 5. I believe this is a different error than #3028 -- because this is specific to not having a real version in the package.json file. And it is very inconsistent when it wants to crop up and fail. I have not figured out when/why it occurs; as it is random, but when it does it will always fail until I deinstall the plugin and re-install the plugin.

Observation: It almost seems like it only occurs during a prepare once the prepare finally succeeds it never has a problem again.

NathanaelA avatar Nov 08 '17 19:11 NathanaelA

I've successfully reproduced this issue by running the following steps:

  1. tns create myApp
  2. cd myApp
  3. tns prepare android
  4. open package.json and remove the tns-android key from it
  5. tns plugin add nativescript-barcodescanner

The problem arises when the platforms dir exists, but the entry for respective runtime in package.json does not exist for some reason. So the issue is not related to local plugins only.

rosen-vladimirov avatar Feb 13 '18 01:02 rosen-vladimirov

Still reproducible with {N} 4.1.

dtopuzov avatar Jun 08 '18 13:06 dtopuzov

I'm having this issue

nodetech-architecture avatar Jul 27 '18 22:07 nodetech-architecture

Still reproducible with {N} 5.1.

miroslavaivanova avatar Feb 01 '19 14:02 miroslavaivanova