Day -2 NativeScript Post Series

NativeScript Plugins – Continued

In our yesterday’s post we saw the difference between how plugins are added in PlayGround and using CLI. The folder structure differs in each case and in the case of CLI, the plugins are added directly to node_modules folder.

Common Scenario of Plugin Version Mismatch

Consider the scenario where we downloaded our project from PlayGround. In this case there was a specific folder with the name of plugin as nativescript-camera. Now let us go and update the package.json at root level and observe what happens when the version of camera plugin is changed from 4.0.2 to 4.0.1

Root Level Version – Changed to 4.0.1

package1

Plugin Folder Inside App Folder – Level Version – 4.0.2

package2

Now let us go and execute the build command and verify the versions of plugin in node_modules folder and app\nativescript-camera folder.

When the build completes, the version of nativescript-camera plugin inside app folder still stays at 4.0.2

Plugin Folder Inside App Folder – Level Version – 4.0.2 – After Build

package3

Now let us observe the package version in node_modules folder.

Plugin Version – Node_Modules – 4.0.1 – After Build

package4

The build commands gets the latest packages based on the version mentioned in the root level package.json file.

Code Snippet Referring 4.0.2 Version of Camera Plugin

package5

Code Snippet Referring 4.0.1 Version from Node_Modules Folder

package6

We can always find the folder from which the plugin is referred by hovering the icon over the plugin name. Visual Studio Code displays the path of the plugin from where the plugin is referred.

package7

This feature of Visual Studio Code can be used to verify if all the required plugins are referred properly in the code from node_modules folder.

We try to download sample projects from market place or play ground. It is always better to remove the plugin from app folder before proceeding development to ensure we can maintain and update the plugins version by changing the root level package.json.

We might not be able to find the plugin version mismatch until we run the app on the device as the build process does not detect the mismatch.

We can use the plugin inside app folder, only when we don’t want to get the changes with respect to plugin.

Happy Reading !!!

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s