`getExportedDeclarations` not working with yarn PnP
See original GitHub issueDescribe the bug
Version: 11.0.0
I’m in the process of migrating a project to Yarn v3, including the Plug’n’Play functionality.
My project is structured as a TypeScript monorepo. The documentation is generated using ts-morph
. Since the switch, that is failing, because getExportedDeclarations()
is returning an empty array for re-exported types from another package of the monorepo. Many other types have become any
.
I suspect this is because ts-morph is not compatible with Yarn PnP out of the box, but I’m not sure how to make it work to be honest.
To Reproduce
This is somewhat tricky to reproduce, but you can use my repo to do so.
- clone https://github.com/zwave-js/node-zwave-js
- check out commit
eb20fcb
- run
yarn add --dev ts-morph
(so yarn PnP doesn’t barf at you) - create a file
repro.ts
with the following content in the root:
import { Project } from "ts-morph";
import { tsConfigFilePath } from "./packages/maintenance/src/tsAPITools";
const program = new Project({ tsConfigFilePath });
const file = program.getSourceFile("packages/zwave-js/src/index.ts");
const identifier = "ValueID";
const decl = file?.getExportedDeclarations().get(identifier);
debugger;
- run this in a debugging console:
yarn node -r ts-node/register repro.ts
Expected behavior
decl
should be an array with length 1, including the original symbol for ValueID
.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5
Top Results From Across the Web
Troubleshooting | Yarn
If you get it, it very likely means that your application is not running with the PnP resolver, meaning that your require calls...
Read more >ts-simple-ast - Bountysource
Hi, I'm working on some TS/JS projects, and this tool really helped me, ... Support automatically determining if a string literal should be...
Read more >What is Yarn PNP and Should You Use It? - Atomic Spin
Yarn PNP (Plug'n'Play) can make installation faster and provide better strictness around transitive dependencies. Is it worth using?
Read more >Getting started with Yarn 2: Ambiguous imports | by xsmith
After opening an issue over on Yarn, Maël mentioned a fix was to use Node.js' module. ... since it should only run when...
Read more >Yarn not recognizing built in package? - Stack Overflow
I am now trying to migrate to Yarn 2 with PnP and in that, trying to fix anything yarn dlx @yarnpkg/doctor finds, as...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was able to work around this for now by using yarn’s patch protocol to require
typescript
from withints-morph
with the PnP API enabled:5085a05
(#2913)It seems like the way ts-morph imports typescript cannot be effected by yarn PnP api. From this comment ts-morph decided to include typescript bundle as hard-copy. Because yarn enables PnP by patching typescript, including typescript like this way (not by using package json -
dependencies
) ts-morph cannot be compatible with yarn pnp.So patching
@ts-morph/common
is one of the fast workarounds. Just fix import statement(this is similar to what @AlCalzone did, details can be changed). You can use yarn patch, patch-package, or anything else.I’m not sure if ts-morph should change this behavior, to support yarn pnp. Anyway this kind of bundle process (hard copy typescript dist file) is not regular way as I know, so we should think about it (although the comment said there was a
hell
when ts-morph serves typescript as dependency)…? @dsherret