Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

385
Views
TypeScript: Cannot import a type from a separate file in local dependency?

I have two local packages, package1 and package2, and I want to use a TypeScript type Car declared in a separate file in and exported from package1 in package2.

The structure of package1 is:

package1/
  src/
    index.ts
    car.d.ts
  lib/
    index.d.ts // generated
  tsconfig.json
  package.json

index.ts from package1 has only a single line:

export {Car} from './car';

So it's just re-exporting the type declared in car.d.ts, which may be something like

export interface Car {
  brand: string;
};

Now I want to use local package package1 in local package package2. After running

npm i local/path/to/package1

I get the following structure for package2:

package2/
  src/
    index.ts
  lib/
  node_modules/
    package1/  // link to other package
  tsconfig.json
  packjage.json

Everything ok so far. index.ts from package2 now tries to import Car:

import {Car} from './package1';

But that does not work; more precisely, Car is suddenly interpreted as a synonym to any (so typing does not work)! Even worse, I cannot compile package2 because applying tsc to it gives me: "error TS2307: Cannot find module './car' or its corresponding type declarations."

My tsconfig.json for both packages is the following:

{
  "compilerOptions": {
    "target": "es2016",
    "module": "commonjs",
    "declaration": true,
    "strict": true,

    "removeComments": false,

    "sourceMap": true,
    "declarationMap": true,

    "downlevelIteration": true,
    "esModuleInterop": true,

    "rootDir": "./src",
    "outDir": "./lib"
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules", "**/*.spec.ts"]
}
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!