Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

199
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda