简体   繁体   中英

Module elasticsearch not found within Angular2 (AngularCLI)

I try to use the Elasticsearch NPM Module in my Angular2 App.

I import it within my service using:

import { Client, SearchResponse } from 'elasticsearch';

Typescript Compiler does not complain, but ng serve outputs:

Cannot find module 'elasticsearch'

Same happens if I try to use:

import { Client, SearchResponse } from '../../node_modules/elasticsearch/webpack_config/angular.js';

install the typings for it :

npm i @types/elasticsearch@0.0.7

Also , have a look at your tsconfig.json and make sure it's in there as well :

Older version of typescript :

   "types": [    
      "elasticsearch"
    ]

New version of typescript ( >2)

"typeRoots": [
      "node_modules/@types"
    ]

Uninstall all the packages of elastic search if already done so... using commands like..

npm uninstall elasticsearch
npm uninstall -g elasticsearch
npm uninstall -g --save-dev elasticsearch
npm uninstall @types/elasticsearch

Now using the angular-cli install the type definitions for elastic search package on your project

npm install @types/elasticsearch

Now install the elastic search package

npm install elasticsearch

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM