<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Davy De Waele</title>
    <description>The latest articles on DEV Community by Davy De Waele (@ddewaele).</description>
    <link>https://dev.to/ddewaele</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1234817%2F9942c83d-7c7c-434b-9b49-2e3195288b74.png</url>
      <title>DEV Community: Davy De Waele</title>
      <link>https://dev.to/ddewaele</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ddewaele"/>
    <language>en</language>
    <item>
      <title>TypeScript Frustration TSFR-001 : Yarn 4 / PnP and dependency resolution</title>
      <dc:creator>Davy De Waele</dc:creator>
      <pubDate>Wed, 06 Aug 2025 05:32:08 +0000</pubDate>
      <link>https://dev.to/ddewaele/typescript-frustration-tsfr-001-yarn-4-pnp-and-dependency-resolution-1i8</link>
      <guid>https://dev.to/ddewaele/typescript-frustration-tsfr-001-yarn-4-pnp-and-dependency-resolution-1i8</guid>
      <description>&lt;p&gt;I’ve decided to write-up a weekly report of all the frustrating things I encounter with the JavaScript / TypeScript eco-system during my development adventures.&lt;/p&gt;

&lt;p&gt;I’m not by all means a professional JavaScript developer, but I have done several TypeScript projects over the years. And what I keep realizing is I am still lacking some of that core knowledge and experience, as I am sure is also the case for the vast majority of JavaScript developers. Combine that with the fast moving pace of JavaScript frameworks / tooling-chains and you can set yourself up for disaster.&lt;/p&gt;

&lt;p&gt;I will try to describe the issue as best as I can and when possible also describe the solution.&lt;/p&gt;

&lt;p&gt;I think it's a good way to get a more fundamental understanding on how things work and hopefully it will help others.&lt;/p&gt;

&lt;p&gt;So …. without further ado, here’s the frustration of the day : &lt;/p&gt;

&lt;p&gt;*&lt;em&gt;TS2307: Cannot find module x or its corresponding type declarations when using Yarn4 and PnP&lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkn9do5bfi80u9w3ydyhe.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkn9do5bfi80u9w3ydyhe.webp" alt="Funny typescript bug image" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The issue&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Using Yarn 4 as a package manager with PnP (Plug And Play) enabled (the default), I am able to run my typescript code via tsx , but it fails during compilation , and my code editor is also showing errors. (TS2307: Cannot find module .. or its corresponding type declarations.)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The context&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Every JavaScript developer is probably familiar with npm and node_modules. When Yarn (classic) came along it continued using node_modules but a new iteration of Yarn v2 (called berry) moved away from that and started using PnP (Plug And Play) as the new way of resolving nodejs dependencies&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The solution (for those that are in a hurry)&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;It appears that default yarn 4 that is used on my system (4.3.1) has an issue resolving dependencies when using PnP. It attempts to look for dependencies in node_modules despite the fact that PnP is used. This issue was present up until 4.5.1 and appears to have been fixed in 4.5.2 and upwards. Specifying a more recent version of the package manager in package.json fixed the issue.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  The project
&lt;/h2&gt;

&lt;p&gt;I have a project with the following typescript source. It features a single import from the @langchain/core module&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { ChatPromptTemplate } from "@langchain/core/prompts";

const prompt = ChatPromptTemplate.fromTemplate(
    `Answer the following question to the best of your ability:\n{question}`
);

console.log(await prompt.format({ question: "What is the answer to life, the universe, and everything?" }));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The yarn package manager
&lt;/h2&gt;

&lt;p&gt;I had bootstrapped the project with yarn (notice how it defaults to 4.3.1 — more on that later).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn init -y
➤ YN0000: · Yarn 4.3.1
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: · Done in 0s 20ms
The @langchain/core dependency
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I have installed the @langchain/core dependency with yarn&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; yarn add @langchain/core
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0013: │ @langchain/core@npm:0.3.66 can't be found in the cache and will be fetched from the remote registry
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0000: └ Completed
➤ YN0000: Done with warnings in 0s 215ms
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I also added the &lt;strong&gt;tsx&lt;/strong&gt; and &lt;strong&gt;typescript&lt;/strong&gt; dependencies&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add -D typescript
yarn add -D tsx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;My package.json looks fine&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "myproject",
  "packageManager": "yarn@4.3.1",
  "type": "module",
  "scripts": {
    "tsx": "tsx"
  },
  "dependencies": {
    "@langchain/core": "^0.3.66"
  },
  "devDependencies": {
    "tsx": "^4.20.3",
    "typescript": "^5.9.2"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Running via tsx / IDE
&lt;/h2&gt;

&lt;p&gt;I can run the TypeScript file just fine from the command line using &lt;strong&gt;tsx&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn run tsx src/index.ts
Human: Answer the following question to the best of your ability:
What is the answer to life, the universe, and everything?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I can run it fine from my IDE&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhg52l9qm79al55guqjky.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhg52l9qm79al55guqjky.webp" alt="Run Debug Config" width="800" height="516"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fozlwduemacjsfsjmfild.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fozlwduemacjsfsjmfild.webp" alt="Console output" width="800" height="231"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  TypeScript errors in IDE and TSC
&lt;/h2&gt;

&lt;p&gt;But when I look at the sources in my IDE it keeps saying&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TS2307: Cannot find module @langchain/core/prompts or its corresponding type declarations.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw5f8wmhgcaokm4j33kvs.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw5f8wmhgcaokm4j33kvs.webp" alt=" " width="800" height="288"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This also doesn’t seem to be a WebStorm issue as issuing the &lt;strong&gt;tsc&lt;/strong&gt; command on the command line results in a similar error&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn tsc
src/index.ts:1:36 - error TS2307: Cannot find module '@langchain/core/prompts' or its corresponding type declarations.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So why is that ?&lt;/p&gt;

&lt;p&gt;It is weird as you can see that it has picked up the &lt;code&gt;@langchain/core&lt;/code&gt; as an external dependency, and it should be able to resolve the &lt;code&gt;@langchain/core/prompts&lt;/code&gt; import&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpjetzi8p8v64mrh68b6g.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpjetzi8p8v64mrh68b6g.webp" alt=" " width="800" height="888"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And if I do a reveal in finder I can see that it resolves the dependency from the following file&lt;/p&gt;

&lt;p&gt;&lt;em&gt;~/.yarn/berry/cache/@langchain-core-npm-0.3.66-d2b05db5ca-10c0.zip&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fif5pzq8j6lvodsyly26g.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fif5pzq8j6lvodsyly26g.webp" alt=" " width="551" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and indeed inside that zip file we have the correct path&lt;/p&gt;

&lt;h2&gt;
  
  
  The issue ?
&lt;/h2&gt;

&lt;p&gt;So it appears that &lt;strong&gt;tsc&lt;/strong&gt; is not working when &lt;strong&gt;4.3.1&lt;/strong&gt; is used as the package manager&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;base ❯ yarn install
➤ YN0000: · Yarn 4.3.1
➤ YN0000: ┌ Resolution step
➤ YN0085: │ + typescript@patch:typescript@npm%3A5.9.2#optional!builtin&amp;lt;compat/typescript&amp;gt;::version=5.9.2&amp;amp;hash=379a07
➤ YN0085: │ - typescript@patch:typescript@npm%3A5.9.2#optional!builtin&amp;lt;compat/typescript&amp;gt;::version=5.9.2&amp;amp;hash=cef18b
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0000: └ Completed
➤ YN0000: · Done with warnings in 0s 146ms

~/Projects/AgenticAI/typescript-debug-langchainjs-yarn-portal3/myproject master*
base ❯ yarn tsc
src/index.ts:1:36 - error TS2307: Cannot find module '@langchain/core/prompts' or its corresponding type declarations.

1 import { ChatPromptTemplate } from "@langchain/core/prompts";
                                     ~~~~~~~~~~~~~~~~~~~~~~~~~


Found 1 error in src/index.ts:1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;U*&lt;em&gt;pgrading to 4.5.2 fixes the issue&lt;/em&gt;*&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;base ❯ yarn install
➤ YN0000: · Yarn 4.5.2
➤ YN0000: ┌ Resolution step
➤ YN0085: │ + typescript@patch:typescript@npm%3A5.9.2#optional!builtin&amp;lt;compat/typescript&amp;gt;::version=5.9.2&amp;amp;hash=5786d5
➤ YN0085: │ - typescript@patch:typescript@npm%3A5.9.2#optional!builtin&amp;lt;compat/typescript&amp;gt;::version=5.9.2&amp;amp;hash=379a07
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0000: └ Completed
➤ YN0000: · Done with warnings in 0s 148ms

~/Projects/AgenticAI/typescript-debug-langchainjs-yarn-portal3/myproject master*
base ❯ yarn tsc

WORKS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When doing a &lt;code&gt;yarn tsc — traceResolution&lt;/code&gt; you can indeed see that with 4.5.2 it is resolving the dependency via the berry cache (PnP)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;base ❯ yarn tsc --traceResolution
======== Resolving module '@langchain/core/prompts' from '/Users/davydewaele/Projects/AgenticAI/typescript-debug-langchainjs-yarn-portal2/myproject/src/index.ts'. ========
Explicitly specified module resolution kind: 'Node10'.
Loading module '@langchain/core/prompts' from 'node_modules' folder, target file types: TypeScript, Declaration.
Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.
Found 'package.json' at '/Users/davydewaele/.yarn/berry/cache/@langchain-core-npm-0.3.66-d2b05db5ca-10c0.zip/node_modules/@langchain/core/package.json'.
'package.json' does not have a 'typesVersions' field.
File '/Users/davydewaele/.yarn/berry/cache/@langchain-core-npm-0.3.66-d2b05db5ca-10c0.zip/node_modules/@langchain/core/prompts.ts' does not exist.
File '/Users/davydewaele/.yarn/berry/cache/@langchain-core-npm-0.3.66-d2b05db5ca-10c0.zip/node_modules/@langchain/core/prompts.tsx' does not exist.
File '/Users/davydewaele/.yarn/berry/cache/@langchain-core-npm-0.3.66-d2b05db5ca-10c0.zip/node_modules/@langchain/core/prompts.d.ts' exists - use it as a name resolution result.
'package.json' does not have a 'peerDependencies' field.
Resolving real path for '/Users/davydewaele/.yarn/berry/cache/@langchain-core-npm-0.3.66-d2b05db5ca-10c0.zip/node_modules/@langchain/core/prompts.d.ts', result '/Users/davydewaele/.yarn/berry/cache/@langchain-core-npm-0.3.66-d2b05db5ca-10c0.zip/node_modules/@langchain/core/prompts.d.ts'.
======== Module name '@langchain/core/prompts' was successfully resolved to '/Users/davydewaele/.yarn/berry/cache/@langchain-core-npm-0.3.66-d2b05db5ca-10c0.zip/node_modules/@langchain/core/prompts.d.ts' with Package ID '@langchain/core/prompts.d.ts@0.3.66'. ========
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When doing a &lt;code&gt;yarn tsc — traceResolution&lt;/code&gt; you can indeed see that with 4.5.1 it is resolving trying to resolve the dependency via node_modules&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;base ❯ yarn tsc --traceResolution
======== Resolving module '@langchain/core/prompts' from '/Users/davydewaele/Projects/AgenticAI/typescript-debug-langchainjs-yarn-portal3/myproject/src/index.ts'. ========
Explicitly specified module resolution kind: 'Node10'.
Loading module '@langchain/core/prompts' from 'node_modules' folder, target file types: TypeScript, Declaration.
Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.
Directory '/Users/davydewaele/Projects/AgenticAI/typescript-debug-langchainjs-yarn-portal3/myproject/src/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'langchain__core/prompts'
Directory '/Users/davydewaele/Projects/AgenticAI/typescript-debug-langchainjs-yarn-portal3/myproject/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'langchain__core/prompts'
Directory '/Users/davydewaele/Projects/AgenticAI/typescript-debug-langchainjs-yarn-portal3/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'langchain__core/prompts'
Directory '/Users/davydewaele/Projects/AgenticAI/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'langchain__core/prompts'
Directory '/Users/davydewaele/Projects/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'langchain__core/prompts'
Directory '/Users/davydewaele/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'langchain__core/prompts'
Directory '/Users/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'langchain__core/prompts'
Directory '/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'langchain__core/prompts'
Loading module '@langchain/core/prompts' from 'node_modules' folder, target file types: JavaScript, JSON.
Searching all ancestor node_modules directories for fallback extensions: JavaScript, JSON.
Directory '/Users/davydewaele/Projects/AgenticAI/typescript-debug-langchainjs-yarn-portal3/myproject/src/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/davydewaele/Projects/AgenticAI/typescript-debug-langchainjs-yarn-portal3/myproject/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/davydewaele/Projects/AgenticAI/typescript-debug-langchainjs-yarn-portal3/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/davydewaele/Projects/AgenticAI/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/davydewaele/Projects/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/davydewaele/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/node_modules' does not exist, skipping all lookups in it.
Directory '/node_modules' does not exist, skipping all lookups in it.
======== Module name '@langchain/core/prompts' was not resolved. ========
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By using PnP you also need to be aware that the out of the box node will not be able to resolve these modules. If you attempt to launch your compiled javascript using node it will fail&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;base ❯ node index.js
node:internal/modules/esm/resolve:854
  throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), null);
        ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@langchain/core' imported from /Users/davydewaele/Projects/AgenticAI/typescript-debug-langchainjs-yarn-portal3/myproject/dist/index.js
    at packageResolve (node:internal/modules/esm/resolve:854:9)
    at moduleResolve (node:internal/modules/esm/resolve:927:18)
    at defaultResolve (node:internal/modules/esm/resolve:1169:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:540:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:509:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:239:38)
    at ModuleWrap.&amp;lt;anonymous&amp;gt; (node:internal/modules/esm/module_job:96:40)
    at link (node:internal/modules/esm/module_job:95:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v20.17.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you bootstrap node using yarn it will work&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;base ❯ yarn node index.js
Human: Answer the following question to the best of your ability:
What is the answer to life, the universe, and everything?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this is because here yarn will inject your &lt;code&gt;.pnp.cjs&lt;/code&gt; loader into node, allowing node to resolve your packages via PnP.&lt;/p&gt;

&lt;h2&gt;
  
  
  Things I’ve learned along the way
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Package managers matter. I never noticed the packageManager field in package.json or used &lt;strong&gt;CorePack&lt;/strong&gt; to install a package manager.
I didn’t know what CorePack was&lt;/li&gt;
&lt;li&gt;Didn’t realize there such a thing as &lt;strong&gt;Yarn Classic&lt;/strong&gt; (v1) using &lt;strong&gt;node_modules&lt;/strong&gt;, and Yarn v2 / v3 / v4 using &lt;strong&gt;PnP&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;I didn’t know you need to use yarn to bootstrap node if you are working in PnP environment&lt;/li&gt;
&lt;li&gt;Despite the fact that these things have been around for a while, stuff still breaks easily, and you always need to make sure you know what versions you are using, and see if upgrading them will fix your issues.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Latest versions of &lt;strong&gt;Yarn&lt;/strong&gt; and &lt;strong&gt;PnP&lt;/strong&gt; introduce a totally new way of resolving node modules. There is no &lt;strong&gt;node_modules&lt;/strong&gt; folder anymore and it seems that the default version of Yarn that my system defaulted to (4.3.1) still has issues with how modules get resolved. Only after enabling the traceResolution I was able to see that it was looking for dependencies in &lt;strong&gt;node_modules&lt;/strong&gt; , something it shouldn’t do when using PnP.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
