Skip to content

Unable to find type definitions that are provided by the package rather than @types when not using commonjs #14470

@phurytw

Description

@phurytw

I'm trying to compile in ES2015 but the compiler fails to find Redux's type definitions. The definitions are located in the Redux package itself (not @types). This works with module: "commonjs" compiler option but not with any other module system.

I can't import it with a triple-slash reference (/// <reference path="node_modules/redux/index.d.ts" />) neither because the file doesn't have a declare module statement. And doing it with types (/// <reference types="redux" />) will fail because there is no file in @types/redux.

That being said I can work around it by copying the node_modules/redux/index.d.ts file to node_modules/@types/redux/index.d.ts or by wrapping the whole type definition file into a declare module "redux".

I also tried to fiddle with the typeRoots and types compiler options. The best that came out of it is adding node_modules to typeRoots to it successfully locates the Redux package with its index.d.ts however I will get an error for each of every other directory. Something like this:

error TS2688: Cannot find type definition file for '.bin'.
error TS2688: Cannot find type definition file for '@types'.
error TS2688: Cannot find type definition file for 'js-tokens'.
error TS2688: Cannot find type definition file for 'lodash'.
error TS2688: Cannot find type definition file for 'lodash-es'.
error TS2688: Cannot find type definition file for 'loose-envify'.

TypeScript Version: 2.1.1 (Windows)

Code

import { createStore } from "redux";

tsconfig.json

{
    "compilerOptions": {
        "module": "es2015"
    }
}

Expected behavior:
Compiles succesfully
Actual behavior:
Error thrown error TS2307: Cannot find module 'redux'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions