Skip to content

Error when building a file that imports .d.ts file (no .ts file) #744

@pcowgill

Description

@pcowgill

Current Behavior

TSDX (probably Rollup behind the scenes) struggles with building a src/index.ts file that imports generated types. Here's a repo with a reproduction: https://github.com/pcowgill/tsdx-typechain/

This line - import { Greeter } from "../typechain/Greeter"; - isn't working.

Greeter is a .d.ts file.

I might need to configure Rollup via TSDX, there might be a simple change to the tsconfig.json that can address it, or maybe something else needs to be done.

Error: Could not resolve '../typechain/Greeter' from src/index.ts

    at error (/Users/paulcowgill/Code/tsdx-typechain/node_modules/rollup/dist/shared/node-entry.js:5400:30)

    at ModuleLoader.handleResolveId (/Users/paulcowgill/Code/tsdx-typechain/node_modules/rollup/dist/shared/node-entry.js:12410:24)

    at ModuleLoader.<anonymous> (/Users/paulcowgill/Code/tsdx-typechain/node_modules/rollup/dist/shared/node-entry.js:12298:30)

    at Generator.next (<anonymous>)

    at fulfilled (/Users/paulcowgill/Code/tsdx-typechain/node_modules/rollup/dist/shared/node-entry.js:38:28)

Expected behavior

tsdx build completes and uses the .d.ts type files I imported in src/index.ts.

Suggested solution(s)

I'm not sure if I need a rollup plugin, a different set of choices in tsconfig.json, or something else. If it's a rollup plugin I need, then just some docs for TSDX would be the change to make. If it's a tsconfig.json change, then maybe the default TSDX tsconfig.json could be different to accommodate this type of usage too while still supporting the existing use cases.

Additional context

I used TypeChain to generate the types since it's an Ethereum-related project, but I don't think you need to worry about how the .d.ts types were generated to debug this issue. The type I'm trying to import is here https://github.com/pcowgill/tsdx-typechain/blob/primary/typechain/Greeter.d.ts

Your environment

Software Version(s)
TSDX 0.13.2
TypeScript 3.9.5
Browser n/a
npm/Yarn npm 6.14.4
Node 12.18.0
Operating System macOS 10.15.5

Thanks!!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions