Typescript: Use node module resolution for @types even when targeting non-node modules

Created on 23 Sep 2016  ·  7Comments  ·  Source: microsoft/TypeScript

TypeScript Version: nightly (2.1.0-dev.20160923)

Code

node_modules/@types/a/index.d.ts

export declare class A {}

node_modules/@types/b/index.d.ts

import {A} from "a";
export declare class B extends A {}

tsconfig.json

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

src/foo.ts

May leave this empty.

Expected behavior

node_modules/@types/b/index.d.ts can reference node_modules/@types/a/index.d.ts

Actual behavior

node_modules/@types/b/index.d.ts(1,17): error TS2307: Cannot find module 'a'.

Quick fix

This may be fixed by adding "moduleResolution": "node" to tsconfig.json.

Bug Fixed

Most helpful comment

The quick fix doesn't solve the problem when developing AMD-based projects. All modules defined in the project are in AMD format. If moduleResolution is set to node then these modules can't be imported properly.

All 7 comments

I am sure we had another issue for this, but can not seem to find it.

@andy-ms we should get a fix for this soon as well.

The quick fix doesn't solve the problem when developing AMD-based projects. All modules defined in the project are in AMD format. If moduleResolution is set to node then these modules can't be imported properly.

This will also enable scenario of using Rollup.js for bundling and npm link for linking components / solution projects
(rollup requires ES6 modules, and right now emitting ES6 modules breaks Node module resolution)

@cnshenj What is your workaround for now? We have the same problem with _momentjs_ and _knockout-decorators_

@ViceIce Just keep using typings to get all declaration files for AMD-based projects. Have to wait for TypeScript 2.1 to switch from typings to @types.

@cnshenj If you use relative path then it will work. That's the workaround for me.

Was this page helpful?
0 / 5 - 0 ratings