map7
map7

Reputation: 5126

nativescript using angular-token results in localStorage error

I'm using nativescript 6.1.1 with Angular 8.0 and my backend is Rails 5.x. I'm trying to use a npm plugin called angular-token which I have working in Angular but not in nativescript.

The error I get is;

Installing on device emulator-5554...
Successfully installed on device with identifier 'emulator-5554'.
Restarting application on device emulator-5554...
Successfully synced application org.nativescript.AssetManagementPrototype on device emulator-5554.
JS: HMR: Hot Module Replacement Enabled. Waiting for signal.
JS: Angular is running in the development mode. Call enableProdMode() to enable the production mode.
JS: ERROR Error: Uncaught (in promise): ReferenceError: localStorage is not defined
JS: ReferenceError: localStorage is not defined
JS:     at new AngularTokenService (file:///node_modules/angular-token/fesm5/angular-token.js:40:0)
JS:     at _createClass (file:///node_modules/@angular/core/fesm5/core.js:18515:0)
JS:     at _createProviderInstance (file:///node_modules/@angular/core/fesm5/core.js:18477:0)
JS:     at resolveNgModuleDep (file:///node_modules/@angular/core/fesm5/core.js:18441:0)
JS:     at NgModuleRef_.push.../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (file:///node_modules/@angular/core/fesm5/core.js:19149:0)
JS:     at resolveNgModuleDep (file:///node_modules/@angular/core/fesm5/core.js:18460:0)
JS:     at NgModuleRef_.push.../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (file:///data/data/org.nativescript.AssetManagem...

I've tried adding the @proplugins/nativescript-localstorage to my project, but that didn't help as the plugin angular-token needs to access the localstorage. I forked angular-token and tried adding @proplugins/nativescript-localstorage to it but get a build error here;

BUILD ERROR
projects/angular-token/src/lib/angular-token.service.ts(11,31): error TS7016: Could not find a declaration file for module '@proplugins/nativescript-localstorage'. '/home/map7/code/angular-token/node_modules/@proplugins/nativescript-localstorage/localstorage.js' implicitly has an 'any' type.
  Try `npm install @types/proplugins__nativescript-localstorage` if it exists or add a new declaration (.d.ts) file containing `declare module '@proplugins/nativescript-localstorage';`

Error: projects/angular-token/src/lib/angular-token.service.ts(11,31): error TS7016: Could not find a declaration file for module '@proplugins/nativescript-localstorage'. '/home/map7/code/angular-token/node_modules/@proplugins/nativescript-localstorage/localstorage.js' implicitly has an 'any' type.
  Try `npm install @types/proplugins__nativescript-localstorage` if it exists or add a new declaration (.d.ts) file containing `declare module '@proplugins/nativescript-localstorage';`

    at Object.<anonymous> (/home/map7/code/angular-token/node_modules/ng-packagr/lib/ngc/compile-source-files.js:65:19)
    at Generator.next (<anonymous>)
    at fulfilled (/home/map7/code/angular-token/node_modules/ng-packagr/lib/ngc/compile-source-files.js:4:58)

projects/angular-token/src/lib/angular-token.service.ts(11,31): error TS7016: Could not find a declaration file for module '@proplugins/nativescript-localstorage'. '/home/map7/code/angular-token/node_modules/@proplugins/nativescript-localstorage/localstorage.js' implicitly has an 'any' type.
  Try `npm install @types/proplugins__nativescript-localstorage` if it exists or add a new declaration (.d.ts) file containing `declare module '@proplugins/nativescript-localstorage';`

Error: projects/angular-token/src/lib/angular-token.service.ts(11,31): error TS7016: Could not find a declaration file for module '@proplugins/nativescript-localstorage'. '/home/map7/code/angular-token/node_modules/@proplugins/nativescript-localstorage/localstorage.js' implicitly has an 'any' type.
  Try `npm install @types/proplugins__nativescript-localstorage` if it exists or add a new declaration (.d.ts) file containing `declare module '@proplugins/nativescript-localstorage';`

    at Object.<anonymous> (/home/map7/code/angular-token/node_modules/ng-packagr/lib/ngc/compile-source-files.js:65:19)
    at Generator.next (<anonymous>)
    at fulfilled (/home/map7/code/angular-token/node_modules/ng-packagr/lib/ngc/compile-source-files.js:4:58)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build:lib: `ng build --prod angular-token && cp README.md dist/angular-token`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] build:lib script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/map7/.npm/_logs/2019-09-17T23_53_33_058Z-debug.log

How do I get the angular-token working in NativeScript?

Upvotes: 0

Views: 160

Answers (0)

Related Questions