Skip to content

Cannot resolve .d.ts file -- use import type or triple-slash reference instead #85

@sporritt

Description

@sporritt

What happens and why it is wrong

When compiling a TS file via rollup and the typescript 2 plugin, the .d.ts from which it imports a few things cannot be found.

I have a single Typescript file that I wish to build to a UMD module via rollup. There's a dedicated typescript config file for it, and the rollup config contains 3 instances of this setup (the rollup config given below being just for this one that fails). The directory structure is:

- rollup.config.js
- ts-config
    - ts-config-io.json
- ts
    - io.ts

I run this command from the directory in which rollup.config.js resides:

rollup --config

The top of io.ts looks like this:

import { AClass } from "../types/something-sensitive/index";

I've pasted the verbose output below, but the crux of the matter is this error:

Could not resolve '../types/something-sensitive/index' from ts/io.ts

Am I sure this should work?

idk...with the plugin and rollup? i'm new to the world of rollup. perhaps i missed something. However, if i run this command from the same directory in which rollup.config.js resides:

tsc -p ts-config/tsconfig-io.json

The typescript file is successfully built to JS (with the output going to ts-config\_build\io.js, if that helps).

So have I done something wrong here? Missed a setting or something? I can't tell if rollup is trying to resolve the .d.ts at all, or if it is and it's just in some other working directory etc. Another of the TS files I build in this same rollup config file, with the exact same rollup settings, does not import any typings and everything works as expected - the JS is built and rollup, er, rolls it up.

Any suggestions you could make would be appreciated.

Environment

i'm on a mac; i doubt this has anything to do with the situation.

Versions

  • typescript: 2.6.2
  • rollup: 0.58.2
  • rollup-plugin-typescript2: 0.13.0

rollup.config.js

{
        input: 'ts/io.ts',
        output: [{
            name: 'SomeIOThing',
            file: '_build/io.js',
            format: 'umd'
        }],
        plugins: [
            typescript({

                check: true,
                verbosity: 3,
                clean: true,
                rollupCommonJSResolveHack: false,
                typescript: require("typescript"),

                tsconfig: "./ts-config/tsconfig-io.json",
                tsconfigOverride: {
                    compilerOptions: { }
                }
            })
        ]
    }

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "es2015",
    "outDir": "_build",
    "moduleResolution": "node",
    "sourceMap": true,
    "declaration":true,
    "emitDecoratorMetadata": false,
    "experimentalDecorators": false,
    "lib": [ "es2015", "dom" ],
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true

  },
  "files":[ "../ts/io.ts" ]
}

package.json

"rollup": "^0.58.2",
    "rollup-plugin-node-resolve": "^3.3.0",
    "rollup-plugin-typescript2": "^0.13.0",

(although note that the node resolve plugin is unused)

plugin output with verbosity 3

ts/io.ts    "clean": true,
 → _build/io.js    "rollupCommonJSResolveHack": false,
...    "typescript": "version 2.6.2",

    "tsconfig": "./ts-config/tsconfig-io.json",
    "tsconfigOverride": {
        "compilerOptions": {}
    },
    "cacheRoot": "/something-sensitive/.rpt2_cache",
    "include": [
        "*.ts+(|x)",
        "**/*.ts+(|x)"
    ],
    "exclude": [
        "*.d.ts",
        "**/*.d.ts"
    ],
    "abortOnError": true,
    "useTsconfigDeclarationDir": false,
    "tsconfigDefaults": {}
}
rpt2: rollup config:
{
    "external": [
        "",
        ""
    ],
    "input": "ts/io.ts",
    "chunkGroupingSize": 5000,
    "perf": false,
    "plugins": [
        {
            "name": "rpt2"
        }
    ],
    "entry": "ts/io.ts"
}
rpt2: built-in options overrides: {
    "noEmitHelpers": false,
    "importHelpers": true,
    "noResolve": false,
    "noEmit": false,
    "outDir": "/something-sensitive",
    "moduleResolution": 2,
    "declarationDir": "/something-sensitive"
}
rpt2: parsed tsconfig: {
    "options": {
        "module": 5,
        "target": 1,
        "outDir": "/something-sensitive",
        "moduleResolution": 2,
        "sourceMap": true,
        "declaration": true,
        "emitDecoratorMetadata": false,
        "experimentalDecorators": false,
        "lib": [
            "lib.es2015.d.ts",
            "lib.dom.d.ts"
        ],
        "noImplicitAny": true,
        "suppressImplicitAnyIndexErrors": true,
        "noEmitHelpers": false,
        "importHelpers": true,
        "noResolve": false,
        "noEmit": false,
        "declarationDir": "/something-sensitive",
        "configFilePath": "/something-sensitive/./ts-config/tsconfig-io.json"
    },
    "fileNames": [
        "/something-sensitive/ts/io.ts"
    ],
    "typeAcquisition": {
        "enable": false,
        "include": [],
        "exclude": []
    },
    "raw": {
        "compilerOptions": {
            "module": "es2015",
            "target": "es5",
            "outDir": "_build",
            "moduleResolution": "node",
            "sourceMap": true,
            "declaration": true,
            "emitDecoratorMetadata": false,
            "experimentalDecorators": false,
            "lib": [
                "es2015",
                "dom"
            ],
            "noImplicitAny": true,
            "suppressImplicitAnyIndexErrors": true
        },
        "files": [
            "../ts/io.ts"
        ]
    },
    "errors": [],
    "wildcardDirectories": {},
    "compileOnSave": false,
    "configFileSpecs": {
        "filesSpecs": [
            "../ts/io.ts"
        ],
        "excludeSpecs": [
            "_build"
        ],
        "validatedExcludeSpecs": [
            "_build"
        ],
        "wildcardDirectories": {}
    }
}
rpt2: included:
'[
    "*.ts+(|x)",
    "**/*.ts+(|x)"
]'
rpt2: excluded:
'[
    "*.d.ts",
    "**/*.d.ts"
]'
rpt2: Ambient types:
rpt2:     /something-sensitive/node_modules/@types/estree/index.d.ts
rpt2:     /something-sensitive/node_modules/@types/node/index.d.ts
rpt2: ambient types changed, redoing all semantic diagnostics
rpt2: transpiling '/something-sensitive/ts/io.ts'
rpt2:     cache: '491e0fb3838a963f725831db27ee532c020c6ebf'
rpt2:     cache miss
rpt2:     cache: '491e0fb3838a963f725831db27ee532c020c6ebf'
rpt2:     cache miss
rpt2:     cache: '491e0fb3838a963f725831db27ee532c020c6ebf'
rpt2:     cache miss
rpt2: generated declarations for '/something-sensitive/ts/io.ts'
[!] Error: Could not resolve '../types/something-sensitive/index' from ts/io.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions