【问题标题】:Installing angular2-localstorage in WebStorm gives error regarding "typings install"在 WebStorm 中安装 angular2-localstorage 会出现有关“类型安装”的错误
【发布时间】:2017-03-05 00:41:02
【问题描述】:

我正在使用 Windows 和 WebStorm。尝试使用npm install angular2-localstorage 安装angular2-localstorage,但出现错误。

angular2-localstorage 项目没有维护,所以我在这里发帖。

https://github.com/marcj/angular2-localStorage

错误详情:

npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "angular2-localstorage"
npm ERR! node v6.10.0
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE

npm ERR! angular2-localstorage@0.4.0 postinstall: `typings install`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the angular2-localstorage@0.4.0 postinstall script 'typings install'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the angular2-localstorage package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     typings install
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs angular2-localstorage
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls angular2-localstorage
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\***\WebstormProjects\ReusGooRoo2\npm-debug.log

日志文件内容:http://pastebin.com/njG9XMgK

任何帮助表示赞赏。

【问题讨论】:

  • 您是否安装了全球性的打字机?

标签: javascript angular webstorm npm-install


【解决方案1】:

由于节点模块angular2-localstorage 没有正确维护,我会推荐 angular-2-local-storage node_module 作为替代。

步骤:

  1. 安装npm install angular-2-local-storage
  2. 确保在 config.js(systemjs 或 webpack)中添加了包
  3. 如下导入模块和服务

    import { LocalStorageModule,LocalStorageService} from 'angular-2-local-storage';
    
  4. 将模块添加到导入数组和服务到提供程序数组

     imports: [ BrowserModule,
       LocalStorageModule.withConfig({storageType: 'localStorage'}), ],
    
     providers:[LocalStorageService],
    
  5. 将服务作为依赖注入到组件中,如下所示

    constructor(private localStorageService: LocalStorageService) {
            this.name = 'Angular-2-Local-Storage-Demo';
            this.localStorageService.add('a',this.user);
            console.log(this.localStorageService.get('a')); 
            this.valuFromLocalStorage= this.localStorageService.get('a')
    }
    

LIVE DEMO

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-16
    相关资源
    最近更新 更多