0

i'm trying to use the localstorage NativeScript module located at

https://www.npmjs.com/package/nativescript-localstorage

I have a LocalStorage service coppied from a web app that I want to use with a NativeScript app, I installed the module successfully with tns plugin add nativescript-localstorage. The first thing i'm confused about is: My app is written in Typescript and this module is written in Javascript would I be able to import/use this module in my app? I added the following to the imports section of my LocalStorageService: var localStorage = require('nativescript-localstorage'); The app built fine but after it got deployed I got the following error:

error: Error: com.tns.NativeScriptException: Failed to find module: "nativescript-localstorage", relative to: app/tns_modules/

Then I tried: import * as localStorage from 'nativescript-localstorage'; I then get a error saying cannot find module nativescript-localstorage. Any idea what i'm doing wrong?

1 Answer 1

1

That error is not related to the way you import it, rather the fact your platforms/[platform]/[appname]/app/tns_modules folder doesn't include the plugin. Just tns platform remove [platform], tns platform add [platform] and tns run [platform] and you should see it. And be able to require it.

Sign up to request clarification or add additional context in comments.

9 Comments

So does that folder I mentioned contain the plugin at all?
Do I need to import the localstorage module in app.module.ts? at the moment i'm just importing it in the localStorage service
If the module isn't even in you platform folder then importing it will fail as well so let's focus on that first. After adding the plugin and doing a proper build it should end up here for Android: <appfolder>/platforms/android/src/main/assets/app/tns_modules and here for iOS: <appfolder>/platforms/ios/<appname>/app/tns_modules
<appname> isn't in my platforms/android folder at all after doing a build.
I said "<appfolder>/platforms/android/src/main/assets/app/tns_module‌​s" for Android - please share a screenshot or something so we can figure this out.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.