Error when building a file that imports .d.ts file (no .ts file)
See original GitHub issueCurrent 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!!
Issue Analytics
- State:
- Created 3 years ago
- Comments:16
Top GitHub Comments
@agilgur5
tsdx
builds successfully when using theimport type
syntax rather than justimport
.https://github.com/ethereum-ts/TypeChain/issues/247#issuecomment-648139358
Thanks those details are helpful.
Gotcha, yea I’m pretty sure that’s due to #113, which is actually TS’s own behavior – so TSDX and rpt2 don’t diverge on that (as of right now). You’ll need to copy over any declaration files into your
dist/
folder (in the right location) so that they exist after publish as well. Or havetypechain
output to thedist/
folder initially. Basically declaration files are already compiled artifacts so TS doesn’t transform them in any way when compiling, it just references them for type-checking. So you have to manually copy those if you want your consumers to be able to use them too.