Tedious: `error TS2304: Cannot find name 'StringDecoder'.` with v6.6.1

Created on 27 Nov 2019  路  8Comments  路  Source: tediousjs/tedious

When I compile my project,

../../node_modules/@types/readable-stream/index.d.ts:138:18 - error TS2304: Cannot find name 'StringDecoder'.

138         decoder: StringDecoder | null;
                     ~~~~~~~~~~~~~

Node: 10.16.0
Typescript: 3.3.3333
tedious: 6.6.1

It works if I change tedious version to 6.5.0.
Not sure if this is related to https://github.com/tediousjs/tedious/issues/1007

Would anyone advise?

Most helpful comment

An issue about this has already been raised https://github.com/DefinitelyTyped/DefinitelyTyped/pull/37869

Here's the fix: @anthonylau @obermobber . Hopefully this also fixes your issue!
image

All 8 comments

Hi @anthonylau, can you provide some details on how did you compile your project or maybe provide a reproduce script? I have set up the tedious project with the versions that you provide, and the tedious project builds fine. Also, do you want to try your project with a newer version of Typescript since that 3.3.3333 is released about 9 months ago?

Hey @MichaelSun90, I have the same issue as @anthonylau was having. I also fixed it with going for tedious v6.5.0.

running my start scrip ("start": "nodemon --exec ts-node -- ./src/index.ts") does not cause any problems, but running a prod build ("tsc -p tsconfig.json") caused the following error:

node_modules/@types/readable-stream/index.d.ts:138:18 - error TS2304: Cannot find name 'StringDecoder'.

138 decoder: StringDecoder | null;
~~~~~

Found 1 error.

npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build:prod: tsc -p tsconfig.json
npm ERR! Exit status 2

I use it in combination with
sequelize 5.15.1
typescript: 3.3.4000
Node: 10.15.3

What additional information do you need?

additonal info:
going into the index.d.ts, typescript is giving the following problem information:
'StringDecoder' refers to a value, but is being used as a type here. (ts2749)

I've trouble understanding where this issue is coming from -- based on https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6a3064cc7408b4e71d0d0feb6f92457d4c22e15c/types/readable-stream/index.d.ts#L132, there is no reference to StringDecoder but NodeStringDecoder.

Can you check the contents of the node_modules/@types/readable-stream/index.d.ts file on your system?

Yeah I checked, and the ReadableState interface looks as follows:

interface ReadableState {
        objectMode: boolean;
        highWaterMark: number;
        buffer: BufferList<any>;
        length: number;
        pipes: any; // NodeJS.WritableStream | any[]; // TODO
        pipesCount: number;
        flowing: any;
        ended: boolean;
        endEmitted: boolean;
        reading: boolean;
        sync: boolean;
        needReadable: boolean;
        emittedReadable: boolean;
        readableListening: boolean;
        resumeScheduled: boolean;
        destroyed: boolean;
        awaitDrain: number;
        defaultEncoding: string;
        readingMore: boolean;
        decoder: StringDecoder | null;
        encoding: string | null;

        // new (options: ReadableStateOptions, stream: _Readable): ReadableState;
    }

This is the tedious dependency that it has installed:

"readable-stream": {
          "version": "3.4.0",
          "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.4.0.tgz",
          "integrity": "sha512-jItXPLmrSR8jmTRmRWJXCnGJsfy85mB3Wd/uINMXA65yrnFo0cPClFIUWzo2najVNSl+mx7/4W8ttlLWJe99pQ==",
          "requires": {
            "inherits": "^2.0.3",
            "string_decoder": "^1.1.1",
            "util-deprecate": "^1.0.1"
          }

image

So it looks like readable-stream v 2.3.6 has been merged with NodeStringDecoder instead of StringDecoder, however, it might have not been published yet

image

image

This is probably a DefinitelyTyped problem

This is the tedious dependency that it has installed:

I think you're looking at the wrong readable-stream dependency. The problem lies in @Types/readable-dependency, which should have 2.3.5 installed

image

An issue about this has already been raised https://github.com/DefinitelyTyped/DefinitelyTyped/pull/37869

Here's the fix: @anthonylau @obermobber . Hopefully this also fixes your issue!
image

Yeah, was just going to write that!
I installed @types/node: 12.12.17 and the prod build works fine. Thanks!!

Was this page helpful?
0 / 5 - 0 ratings