Can't find variable: document


#1

Hi,

I’m trying to use a third party module within my application. It is: https://www.npmjs.com/package/ngx-store

It utilizes things such as document and window. How do I resolve dependencies which rely on these within my Nativescript application?

Due to the above, I am getting errors such as:

file:///app/vendor.js:113191:49: JS ERROR ReferenceError: Can't find variable: document

When trying to compile my application. Do I need to rewrite some of the dependency to support a Nativescript environment?


#2

I haven’t use this library personally hence not sure what is the purpose. But as you might already know, browser specific apis won’t be available in NativeScript.

  1. You may define objects like global.document = {} in your app root (Core) / app module (Angular), so it won’t be at least undefined. If you like to implement your own wrapper of document function you may do that too in order to make the library functional.
  2. There are plugins like local storage which will implement a browser like local / session storage for your nativescript app.