0

我将 nativescript 6.1.1 与 Angular 8.0 一起使用,我的后端是 Rails 5.x。我正在尝试使用一个名为 angular-token 的 npm 插件,我在 Angular 中工作,但在 nativescript 中没有。

我得到的错误是;

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...

我尝试将 @proplugins/nativescript-localstorage 添加到我的项目中,但这并没有帮助,因为插件 angular-token 需要访问本地存储。我分叉了 angular-token 并尝试将 @proplugins/nativescript-localstorage 添加到其中,但在此处出现构建错误;

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! angular-token-app@0.0.0 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 angular-token-app@0.0.0 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

如何让 angular-token 在 NativeScript 中工作?

4

0 回答 0