Elasticsearch-js: The latest version v7.0.0-rc.1 does not build

Created on 3 Apr 2019  路  19Comments  路  Source: elastic/elasticsearch-js

馃悰 Bug Report

The latest version v7.0.0-rc.1 does not build

To Reproduce

Steps to reproduce the behavior:
Include the module by running the following command
npm install @elastic/elasticsearch --save

Expected behavior

Should build without any errors

However i get the following error
`> tsc

node_modules/@elastic/elasticsearch/lib/Connection.d.ts:77:3 - error TS1165: A computed property name in an ambient context must refer to an expression whose type is a literal type or a 'unique symbol' type.

77 inspect.custom: string;
~~~~
`

Your Environment

  • node version: 8
  • @elastic/elasticsearch version: >=7.0.0
  • os: Mac
  • typescript: 3.4.1
  • tslint: 5.14.0

Other observations

Including @types/elasticsearch would solve the issue however the types support is only for version 5.0.23

bug typescript v8.x

Most helpful comment

Hello!
Did you installed @types/node?

npm i @types/node --save-dev

All 19 comments

Hello!
Did you installed @types/node?

npm i @types/node --save-dev

I am seeing the same issue with @types/node latest installed.

@jlausolutions can you write the following info?

  • node version: ...
  • @elastic/elasticsearch version: ...
  • os: ...
  • typescript: ...

node: v10.0.0
@elastic/elasticsearch: ^7.0.0-rc.1
os: MacOS 10.13.6
typescript: ^3.4.2

I just tried the following:

mkdir tstest && cd tstest
npm init -y
npm i @elastic/elasticsearch typescript @types/node
touch index.ts
./node_modules/.bin/tsc index.ts

index.ts contains the following:

import { Client } from '@elastic/elasticsearch'
const client = new Client({ node: 'http://localhost:9200' })
client.info(console.log)

And everything works as expected.
My system info are:

  • node: v10.15.1
  • @elastic/elasticsearch: ^7.0.0-rc.1
  • os: MacOS 10.14.3
  • typescript: ^3.4.2

I just tried updating node (v10.15.3) and ran the same commands you listed, but am seeing the same error:

node_modules/@elastic/elasticsearch/lib/Connection.d.ts:77:3 - error TS1165: A computed property name in an ambient context must refer to an expression whose type is a literal type or a 'unique symbol' type.

77   [inspect.custom](object: any, options: InspectOptions): string;

Note that it compiled if you run tsc index.ts immediately after touch index.ts, but throws the error after I add the actual index.ts code that includes the import.

Note that it compiled if you run tsc index.ts immediately after touch index.ts, but throws the error after I add the actual index.ts code that includes the import.

Sorry, I thought it was obvious, I compiled the file after writing the code.
Are you using some additional configuration in tsconfig.json?

It was obvious -- I was just working backwards when it was still not working.

In any case, the issue was that I also had tsc installed globally and that was an older version (3.1.3). This could be identified when comparing your line ./node_modules/.bin/tsc index.ts instead of tsc index.ts.

Thanks!

Thanks for the follow-up!
Closing this, feel free to reopen if you still encounter this issue.

Thanks for the follow-up!
Closing this, feel free to reopen if you still encounter this issue.

Hello, I've the same error

My system info are:

  • "@elastic/elasticsearch": "^7.0.0-rc.2"
  • TSC Version 3.4.5
  • Node v10.15.0
  • Windows 10 17134
    I've installed @types/node.
    My tsconfig.json :
    { "compilerOptions": { "module": "commonjs", "esModuleInterop": true, "target": "es2017", "noImplicitAny": true, "moduleResolution": "node", "sourceMap": true, "experimentalDecorators": true, "outDir": "dist", "baseUrl": ".", "paths": { "*": ["node_modules/*", "src/types/*"] } }, "include": ["src/**/*"] }

Hello @lazaro9318!
Can you create a repository with everything needed to reproduce the issue?
Thanks!

I'm also having the same problem. It looks just importing Client will cause the error. The problem also happens with version 5.6.16 and 6.7.0.

@delvedor here is a repo that will case the error when building.

https://github.com/alanjames1987/Elasticsearch-TypeScript-Error

Pull it, run npm i, and then run npm run build:prod to trigger the error.

Additionally, I'm using Node v10.15.3, but since this is TypeScript I doubt it's caused by a problem with Node, but giving more information never hurts.

Hello @lazaro9318!
Can you create a repository with everything needed to reproduce the issue?
Thanks!

I solve the error, deleting the node_modules folder and installing again.

@lazaro9318 Deleting the node_modules folder doesn't solve the problem in any test I've done. It also couldn't solve the problem unless you updated the version number after deleting node_modules and before reinstalling.

Additionally, for anyone else having this problem you can install elasticsearch instead of @elastic/elasticsearch. You will have to change some Elasticsearch code but if you're in a time crunch to get some code released this will at least give you a working codebase.

Apparently, the issue is caused by this line:
https://github.com/elastic/elasticsearch-js/blob/2f92b28bce082d69c2541ee05c3fb059c2c869b8/lib/Connection.d.ts#L79
Because TypeScript does not know how to handle Symbols, or if it does, it does it really bad.

I'll open a pr with a fix.

I can confirm that this pull request works for me.

Waiting for this fix on v6.x

Hello @ariasjose, the fix has already been released in 6.x :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

milu2003 picture milu2003  路  17Comments

georgeedwards picture georgeedwards  路  17Comments

kelaban picture kelaban  路  14Comments

NassiHarel picture NassiHarel  路  10Comments

villasv picture villasv  路  15Comments