Ts-node: Unable to require d.ts file in Lerna project

Created on 12 May 2019  路  3Comments  路  Source: TypeStrong/ts-node

I've got a Lerna project with the following structure:

packages/
  ComponentA/
  ComponentB/
  ...
lerna.json
package.json
tsconfig.json
test.ts

ComponentA does depend on ComponentB, hence some files within it it import it via

# Within component A

import {whatever} from '@project/component-b';

When I try to use ComponentA now within the test.ts file (which is simply called via ts-node test.ts) I get the following error:

TypeError: Unable to require `.d.ts` file.
This is usually the result of a faulty configuration or import. Make sure there is a `.js`, `.json` or another executable extension and loader (attached before `ts-node`) available alongside `index.ts`.

There are currently no .d.ts files at all - but importing via relative paths works fine (e.g. import {whatever} from '../../ComponentB/...';)

ts-node version is v8.0.3.

Most helpful comment

I was having the same issue and I solved it by adding "preserveSymlinks": true to my tsconfig.json file.

All 3 comments

I was having the same issue and I solved it by adding "preserveSymlinks": true to my tsconfig.json file.

That fixed it, thanks a lot.

Confirmed. We upgraded to jest 24 and we ignored the ts-jest incompatibility issues. Then we upgraded ts-jest to 24 and got this error. I noticed the problem occurred in Linux (not Windows). Adding the preserveSymlinks setting resolving the issue.

We are using Lerna in a monorepo setup, if that helps.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

watzon picture watzon  路  3Comments

conordickinson picture conordickinson  路  4Comments

Borewit picture Borewit  路  3Comments

cibergarri picture cibergarri  路  3Comments

motss picture motss  路  4Comments