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

190
Views
tsc requires via package name instead of relative path when emitting declarations

I forked a JavaScript package for another (TypeScript) project as I had to change some things and I wanted it to emit declaration files.

When running tsc locally, everything compiles and the require statements look fine while using relative paths for local files (as desired):

index.d.ts (1):

import Connection = require("./lib/connection");
import Client = require("./lib/client");
import Discovery = require("./lib/discovery");
export { Connection, Client, Discovery, Discovery as discovery };

But when installing it in another project via npm, tsc is invoked during postinstall phase and the generated declarations use require statements with the package name followed by the past instead (this is of course invalid and no typings are gathered by my IDE):

index.d.ts (2):

import Connection = require("@ercksen/esphome-native-api/src/lib/connection");
import Client = require("@ercksen/esphome-native-api/src/lib/client");
import Discovery = require("@ercksen/esphome-native-api/src/lib/discovery");
export { Connection, Client, Discovery, Discovery as discovery };

I found out that running npm run postinstall locally also produces correct results. And manual compilation inside the node_modules/@ercksen/esphome-native-api folder of the referred project also creates faulty declarations. So it has nothing to do with the fact that I create the declarations when installing (instead of pre-built).

The interesting part is: .js files work fine! How can I get that working also for .d.ts files? I think this is not the intended behavior.

Steps to reproduce (you will probably run into issues with my SSL certificate, but that would be a topic for another question):

Following works. See dist/index.d.ts (1)

git clone https://git.ercksen.de/home-automation/esphome-native-api.git
cd esphome-native-api
npm i
tsc

Following does not work. See node_modules/@ercksen/esphome-native-api/index.d.ts (2)

npm i git+https://git.ercksen.de/home-automation/esphome-native-api.git

My tsconfig.json:

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "ES6",
    "outDir": "dist",
    "rootDir": "src",
    "sourceMap": false,
    "allowJs": true,
    "composite": true,
    "skipLibCheck": true,
    "esModuleInterop": true
  },
  "include": [
    "src/**/*"
  ]
}

Any help would be greatly appreciated!

about 4 years ago · Juan Pablo Isaza
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!