Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript refuses to emit files from node_modules with getEmitOutput()

See original GitHub issue

Hi. In out company we use workflow when all packages are written in pure TypeScript and we publish and consume them as-is, without any pre-compilation. I know that it’s slower, but it’s very convenient for developers, because they don’t need to run several parallel tsc --watch processes.

We used webpack and awesome-typescript-loader for this and everything worked fine. But I see that now TypeScript refuses to emit files from node_modules directory using getEmitOutput(), because of isSourceFileFromExternalLibrary check here.

Can we make this configurable?

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:12
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

jjrvcommented, Mar 8, 2018

Outside node_modules TypeScript emits .js files for any .ts files I import, whether they’re listed under files in tsconfig.json or not. This is very nice.

I have a monorepo structured like boennemann/alle. It makes the monorepo very easy to work with, requiring minimal tooling. The trick is to place all code under node_modules so Node’s module lookup strategy will find them without having to create any symlinks.

Unfortunately I’m running into this issue… Now it’s necessary to either omit files, list all of them or use a wildcard. In this case there would be a reasonable strategy: when a .ts file included in files is located under node_modules then for any further .ts files it imports from the same directory or a subdirectory (without entering any deeper node_modules directories), a .js file should still be emitted.

Alternatively a configuration option in tsconfig.json listing paths where .js files should be emitted, whether under node_modules or not, should fix this issue for everyone’s possible use cases.

ahnpnlcommented, Feb 12, 2020

@jjrv said it right. At the moment in ts-jest, either ts-jest has to use Program as fallback or read jest config to solve the issue. I hope TypeScript can solve this natively.

Read more comments on GitHub >

github_iconTop Results From Across the Web

import of library works in javascript file but fails in typescript file
I am trying to import a new module @microsoft/applicationinsights-web into my file test.ts . Unfortunately it says module not found even though ...
Read more >
A Complete Guide to Using TypeScript in Node.js - Better Stack
We are currently set up to compile both JavaScript and TypeScript files, but type checking will not be performed on JavaScript files unless...
Read more >
node_modules/typescript/lib/typescript.d.ts - Google Git
* Gets a type checker that can be used to semantically analyze source files in the program. */. getTypeChecker(): TypeChecker ...
Read more >
TSConfig Reference - Docs on every TSConfig option
A TSConfig file in a directory indicates that the directory is the root of a TypeScript ... Other packages under node_modules/@types/* will not...
Read more >
webpack/webpack - Gitter
getEmitOutput (/home/gchiara/desenvolvimento/webpack/node_modules/ ... What I think is happening is that typescript won't load any .js files because you ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found