<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Davy De Waele on Medium]]></title>
        <description><![CDATA[Stories by Davy De Waele on Medium]]></description>
        <link>https://medium.com/@ddewaele?source=rss-9ac28ff4a11b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*qYVjsDG39QfKJiL3.png</url>
            <title>Stories by Davy De Waele on Medium</title>
            <link>https://medium.com/@ddewaele?source=rss-9ac28ff4a11b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 03:24:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ddewaele/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Debugging TypeScript and LangChain.JS with JetBrains WebStorm]]></title>
            <link>https://medium.com/@ddewaele/debugging-typescript-and-langchain-js-with-jetbrains-webstorm-8ef500af4cf4?source=rss-9ac28ff4a11b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ef500af4cf4</guid>
            <category><![CDATA[langchain]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[webstorm]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Davy De Waele]]></dc:creator>
            <pubDate>Tue, 05 Aug 2025 15:55:14 GMT</pubDate>
            <atom:updated>2025-08-05T15:55:14.603Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>I wanted to do a “quick” write-up on how to create a LangChain.JS app in JetBrains WebStorm and also debug the LangChain.JS framework using TypeScript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hqy0_fkw6gSg-AUBbumyYQ.png" /></figure><p>Having a good development environment, and having the ability to debug and modify code, not only your own code, but also code that you bring into your project from external dependencies is key.</p><p>In this post I will attempt to show you the ins and outs of modern TypeScript debugging using JetBrains WebStorm, and modern package managers like Yarn v2 (PnP).</p><p>I’ll use the @langchain/core dependency from the <a href="https://github.com/langchain-ai/langgraphjs">LangChain.JS </a>open source project.</p><p>We’ll be using a clean setup where we will</p><ul><li>Create a folder structure containing the <a href="https://github.com/langchain-ai/langgraphjs"><strong>LangChain.JS</strong></a> sources and our project</li><li>Create our project that will use <a href="https://github.com/langchain-ai/langgraphjs"><strong>LangChain.JS</strong></a>, a yarn based typescript module</li><li>Write some code in our project that uses <a href="https://github.com/langchain-ai/langgraphjs"><strong>LangChain.JS</strong></a></li><li>Setup our IDE (WebStorm) for debugging</li></ul><p>So lets get things started.</p><h3>Setup the folder structure</h3><p>We’ll create everything in a folder structure called ~/POC/LangChainDebug</p><p>In that folder we will create 2 sub-folders</p><ul><li><strong>langchainjs</strong> : the langchain.js sources</li><li><strong>myproject</strong> : our project</li></ul><p>These reason why we want to have <strong>both our project as well as the LangChain.JS sources</strong> in our workspace is WebStorm will needs this in order to debug files and put breakpoints in them (more on that later)</p><h3>Clone the LangChain.JS project in your workspace</h3><p>We can clone the <strong>LangChain.JS</strong> project using</p><p>git clone <a href="https://github.com/langchain-ai/langchainjs.git">https://github.com/langchain-ai/langchainjs.git</a></p><p>As stated earlier this will allows us to have the LangChainJS sources in our WebStorm workspace.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DANDSeGgvCfRPWCYDbRzKg.png" /></figure><h3>Create our project</h3><h4>Yarn</h4><p>We’re going to use <strong>Yarn</strong> as the package manager for our project. <strong>LangChain.JS</strong> uses Yarn 3 as their package manager so we’ll do the same.</p><p>First thing to do is to check if you have yarn installed. If not you can install it using npm install — global yarn</p><p>This should install <strong>Yarn (classic) v1.22.22</strong></p><pre>yarn -v <br>1.22.22</pre><h4>Bootstrap a new project</h4><p>Next we are going to create a folder called myproject and inside that folder execute yarn init -y</p><pre># perform yarn init<br>$ yarn init -y<br>yarn init v1.22.22<br>warning The yes flag has been set. This will automatically answer yes to all questions, which may have security implications.<br>success Saved package.json<br>Done in 0.02s.</pre><p>This will use <strong>Yarn v1.2.22</strong> to generate a very basic package.json</p><pre># check your package.json<br>$ cat package.json <br>{<br>  &quot;name&quot;: &quot;myproject&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;main&quot;: &quot;index.js&quot;,<br>  &quot;license&quot;: &quot;MIT&quot;<br>}<br><br># notice how your still on version 1.22.22<br>$ yarn -v <br>1.22.22</pre><h4>Upgrading yarn</h4><p><strong>Yarn v1.22.22</strong> is the global yarn that is installed on your system. With yarn we can define what version we want to use on a per project basis.</p><p>We’re going to set our yarn version to a higher version that supports PnP. This is done with the yarn set &lt;version&gt; command</p><p>Depending if you have corepack enabled or not you might see this</p><pre># set yarn version to 3.5.1<br>$ yarn set version 3.5.1<br>➤ YN0000: You don&#39;t seem to have Corepack enabled; we&#39;ll have to rely on yarnPath instead<br>➤ YN0000: Retrieving https://repo.yarnpkg.com/3.5.1/packages/yarnpkg-cli/bin/yarn.js<br>➤ YN0000: Saving the new release in .yarn/releases/yarn-3.5.1.cjs<br>➤ YN0000: Done in 0s 770ms</pre><p>or this if you have corepack enabled.</p><pre>yarn set version 3.5.1<br>! Corepack is about to download https://repo.yarnpkg.com/3.5.1/packages/yarnpkg-cli/bin/yarn.js<br>? Do you want to continue? [Y/n]<br><br>➤ YN0000: Retrieving https://repo.yarnpkg.com/3.5.1/packages/yarnpkg-cli/bin/yarn.js<br>➤ YN0000: Saving the new release in .yarn/releases/yarn-3.5.1.cjs<br>➤ YN0000: Done in 7s 437ms</pre><p>This will generate some extra files (.yarnrc.yml) and will also specify the packageManager in your package.json</p><pre># check the yarnrc file<br>$ cat .yarnrc.yml <br>yarnPath: .yarn/releases/yarn-3.5.1.cjs<br><br># check your package.json <br>$ cat package.json <br>{<br>  &quot;name&quot;: &quot;myproject&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;main&quot;: &quot;index.js&quot;,<br>  &quot;license&quot;: &quot;MIT&quot;,<br>  &quot;packageManager&quot;: &quot;yarn@3.5.1&quot;<br>}</pre><p>Inside that folder you will now have <strong>Yarn v3.5.1</strong> available and if you check the config you will now see that the nodeLinker is set to pnp (the new way of managing dependencies without node_modules )</p><pre># check your yarn version<br>$ yarn -v<br>3.5.1<br><br># check your nodelinker<br>$ yarn config get nodeLinker<br>pnp</pre><blockquote>I do have to note that Yarn v3.5.1 does have an issue with module resolution using PnP. For more information check out</blockquote><blockquote><a href="https://medium.com/@ddewaele/typescript-frustration-tsfr-001-yarn-4-pnp-and-dependency-resolution-fb76be881842">https://medium.com/@ddewaele/typescript-frustration-tsfr-001-yarn-4-pnp-and-dependency-resolution-fb76be881842</a></blockquote><blockquote>So you mightwant to use version 4 by issuing the following command</blockquote><pre>$ yarn set version 4<br>➤ YN0000: Retrieving https://repo.yarnpkg.com/4.9.2/packages/yarnpkg-cli/bin/yarn.js<br>➤ YN0000: Saving the new release in .yarn/releases/yarn-4.9.2.cjs<br>➤ YN0000: Done in 2s 726ms<br><br>$ yarn -v<br>! Corepack is about to download https://repo.yarnpkg.com/4.9.2/packages/yarnpkg-cli/bin/yarn.js<br>? Do you want to continue? [Y/n]<br><br>4.9.2<br></pre><h3>Setting up your IDE</h3><p>Our project will contain a single typescript file that we will use to test the debugging features</p><pre>import { ChatPromptTemplate } from &quot;@langchain/core/prompts&quot;;<br><br>const prompt = ChatPromptTemplate.fromTemplate(<br>    `Answer the following question to the best of your ability:\n{question}`<br>);<br><br>console.log(await prompt.format({ question: &quot;What is the answer to life, the universe, and everything?&quot; }));</pre><p>As you can see we are using a single import and we will debug the fromTemplate method</p><h3>Running the code</h3><p>In order to run this code, we first need to make sure that we have defined yarn as the package manager in our IDE. I am using WebStorm here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*gyoHY-B5zBp3VzoQyWVM-Q.png" /></figure><p>By specifying yarn here, when we execute our TypeScript code via this launch config (using the TypeScript loader)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nRrtsZqsZQmdTKOqCd9oQw.png" /></figure><p>We will see in the console that it executes this comand</p><pre>yarn node \<br>  --import file:/Applications/WebStorm.app/Contents/plugins/nodeJS/js/ts-file-loader/node_modules/tsx/dist/loader.cjs <br>./myproject/src/tools.ts</pre><p>If we would have specified npm as the package manager the launch would fail, as it would be unable to find our @langchain/core dependency because the dependency was added via Yarn / PnP.</p><p>Node is unaware of how to resolve these Yarn / PnP dependencies</p><pre>node \<br>--import file:/Applications/WebStorm.app/Contents/plugins/nodeJS/js/ts-file-loader/node_modules/tsx/dist/loader.cjs <br>./myproject/src/tools.ts<br><br>node:internal/modules/run_main:129<br>    triggerUncaughtException(<br>    ^<br>Error [ERR_MODULE_NOT_FOUND]: Cannot find package &#39;@langchain/core&#39; imported from /Users/davydewaele/Projects/AgenticAI/langchain-debugging/myproject/src/tools.ts<br>    at packageResolve (node:internal/modules/esm/resolve:854:9)<br>    at moduleResolve (node:internal/modules/esm/resolve:927:18)<br>    at defaultResolve (node:internal/modules/esm/resolve:1169:11)<br>    at nextResolve (node:internal/modules/esm/hooks:866:28)<br>    at resolve (file:///Applications/WebStorm.app/Contents/plugins/nodeJS/js/ts-file-loader/node_modules/tsx/dist/esm/index.mjs?1754370131199:2:3893)</pre><h3>External Dependencies</h3><p>Any external dependencies that your project uses will be lised in WebStorm in the External Libraries section.</p><p>So when you package.json contains something like this</p><pre>{<br>  &quot;name&quot;: &quot;myproject&quot;,<br>  &quot;type&quot;: &quot;module&quot;,<br>  &quot;packageManager&quot;: &quot;yarn@4.9.2&quot;,<br>  &quot;devDependencies&quot;: {<br>    &quot;@types/node&quot;: &quot;^24.1.0&quot;,<br>    &quot;tsx&quot;: &quot;^4.20.3&quot;,<br>    &quot;typescript&quot;: &quot;^5.9.2&quot;<br>  },<br>  &quot;dependencies&quot;: {<br>    &quot;@langchain/core&quot;: &quot;^0.3.66&quot;,<br>    &quot;dotenv&quot;: &quot;^17.2.1&quot;,<br>    &quot;zod&quot;: &quot;^4.0.14&quot;<br>  }<br>}</pre><p>You will see this in the WebStorm IDE</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*Ww3WupL7TyYUCUs9DtGvHg.png" /></figure><p>When we CTRL click on a method in our TypeScript source, for example the fromTemplate method</p><pre>const prompt = ChatPromptTemplate.fromTemplate(<br>    `Answer the following question to the best of your ability:\n{question}`<br>);</pre><p>WebStorm will navigate to a typescript definition file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a8sn18mwdHSi4txVtC9KzQ.png" /></figure><p>Now we cannot put breakpoints in a typescript definition files. The only breakpoint we can place here is in a (compiled) javascript file.</p><p>This is obviously not ideal, as you cannot directly jump to the actual source code. You can put breakpoints on these compiled javascript sources, but you would need to look for the fromTemplate method yourself and that can be very cumbersome</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lPfEktGM8Oj0X7MWeQ0auA.png" /></figure><p>The file it jumps to here is located in</p><p><em>~/.yarn/berry/cache/@langchain-openai-npm-0.6.3–020f78a1cd-10c0.zip</em></p><p>This is the yarn pnp equivalent of the `node_modules`. It is called the <strong>global cache directory</strong>.</p><p>Keep in mind that in Yarn PnP, <strong>node_modules</strong> does not exist at all. Instead, Yarn:</p><ul><li>Builds a virtual dependency tree.</li><li>Stores packages in the global cache as ZIP files.</li><li>Resolves them using the .pnp.cjs file (a manifest mapping package names to exact paths inside those ZIPs).</li></ul><p>What you would like is to immediately jump to the correct TypeScript source file and debug from there.</p><h3>Debugging files</h3><p>So how can we jump to these typescript files directly ?</p><p>Well the first thing we can do is add a Yarn portal dependency to add a local package into your project.</p><p>The <strong>portal</strong> feature in Yarn is referred to as a <strong>“portal dependency”</strong>, and it’s part of Yarn’s <strong>“protocols”</strong> system in Plug’n’Play (PnP) and Berry (Yarn 2+). It’s a way to include a <strong>local directory as a dependency</strong>, with <strong>live references</strong> instead of copying or symlinking like in classic npm link.</p><p><strong>The portal </strong>protocol is compatible with PnP and as such we can add the dependency via <strong>Yarn</strong>, and if we compile and / or run our typescript code via Yarn these dependencies will get resolved.</p><pre>base ❯ yarn add @langchain/core@portal:../langchainjs/langchain-core<br>➤ YN0000: · Yarn 4.9.2<br>➤ YN0000: ┌ Resolution step<br>➤ YN0085: │ + @langchain/core@portal:../langchainjs/langchain-core::locator=myproject%40workspace%3A.<br>➤ YN0085: │ - @langchain/core@npm:0.3.66<br>➤ YN0000: └ Completed<br>➤ YN0000: ┌ Fetch step<br>➤ YN0000: └ Completed<br>➤ YN0000: ┌ Link step<br>➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental<br>➤ YN0000: └ Completed<br>➤ YN0000: · Done with warnings in 0s 157ms</pre><p>By executing this command it has removed are standard npm dependency (@langchain/core:0.3.66) and replaced it with a reference to our filesystem</p><p>If you look closely in WebStorm before we had this (a normal dependency, located in the global cache directory of Yarn, containing only the compiled javascript and not the original sources)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CU2axQOMreJScd0TRIZjrw.png" /></figure><p>And now we have this, a dependency that is located on our filesystem, containing the sources just like we cloned it from Github.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Kj06EzdeEzVDWKj26GLmw.png" /></figure><p>However, this in and of itself is not enough. With this portal dependency you will get the following error when trying to compile your typescript project</p><pre>$ yarn tsc<br>src/tools.ts:1:36 - error TS2307: Cannot find module &#39;@langchain/core/prompts&#39; or its corresponding type declarations.<br><br>1 import { ChatPromptTemplate } from &quot;@langchain/core/prompts&quot;;<br>                                     ~~~~~~~~~~~~~~~~~~~~~~~~~<br><br><br>Found 1 error in src/tools.ts:1</pre><p>Also when you attempt to run your file you will get this</p><pre><br>$ yarn tsx src/tools.<br><br>node:internal/modules/run_main:129<br>    triggerUncaughtException(<br>    ^<br>Error: Qualified path resolution failed: we looked for the following paths, but none could be accessed.<br><br>Source path: /Users/davydewaele/Projects/AgenticAI/langchain-debugging/myproject/src/tools.<br>Not found: /Users/davydewaele/Projects/AgenticAI/langchain-debugging/myproject/src/tools.<br><br>    at makeError (/Users/davydewaele/Projects/AgenticAI/langchain-debugging/myproject/.pnp.cjs:7310:34)<br>    at resolveUnqualified (/Users/davydewaele/Projects/AgenticAI/langchain-debugging/myproject/.pnp.cjs:9045:13)<br>    at resolveRequest (/Users/davydewaele/Projects/AgenticAI/langchain-debugging/myproject/.pnp.cjs:9085:14)<br>    at Object.resolveRequest (/Users/davydewaele/Projects/AgenticAI/langchain-debugging/myproject/.pnp.cjs:9141:26)<br>    at resolve$1 (file:///Users/davydewaele/Projects/AgenticAI/langchain-debugging/myproject/.pnp.loader.mjs:2043:21)<br>    at nextResolve (node:internal/modules/esm/hooks:866:28)<br>    at resolveBase (file:///Users/davydewaele/.yarn/berry/cache/tsx-npm-4.20.3-7de67a623f-10c0.zip/node_modules/tsx/dist/esm/index.mjs?1754376226179:2:3811)<br>    at resolveDirectory (file:///Users/davydewaele/.yarn/berry/cache/tsx-npm-4.20.3-7de67a623f-10c0.zip/node_modules/tsx/dist/esm/index.mjs?1754376226179:2:4310)<br>    at resolveTsPaths (file:///Users/davydewaele/.yarn/berry/cache/tsx-npm-4.20.3-7de67a623f-10c0.zip/node_modules/tsx/dist/esm/index.mjs?1754376226179:2:5051)<br>    at resolve (file:///Users/davydewaele/.yarn/berry/cache/tsx-npm-4.20.3-7de67a623f-10c0.zip/node_modules/tsx/dist/esm/index.mjs?1754376226179:2:5428)<br><br>Node.js v20.17.0</pre><p>You can actually see how it tries to resolve <strong>@langchain/core/prompts</strong> by ussing the command yarn tsc — traceResolution</p><pre>$ yarn tsc --traceResolution<br>======== Resolving module &#39;@langchain/core/prompts&#39; from &#39;/Users/davydewaele/Projects/AgenticAI/langchain-debugging/myproject/src/tools.ts&#39;. ========<br>Explicitly specified module resolution kind: &#39;Node10&#39;.<br>Loading module &#39;@langchain/core/prompts&#39; from &#39;node_modules&#39; folder, target file types: TypeScript, Declaration.<br>Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.<br>Found &#39;package.json&#39; at &#39;/Users/davydewaele/Projects/AgenticAI/langchain-debugging/langchainjs/langchain-core/package.json&#39;.<br>&#39;package.json&#39; does not have a &#39;typesVersions&#39; field.<br>File &#39;/Users/davydewaele/Projects/AgenticAI/langchain-debugging/langchainjs/langchain-core/prompts.ts&#39; does not exist.<br>File &#39;/Users/davydewaele/Projects/AgenticAI/langchain-debugging/langchainjs/langchain-core/prompts.tsx&#39; does not exist.<br>File &#39;/Users/davydewaele/Projects/AgenticAI/langchain-debugging/langchainjs/langchain-core/prompts.d.ts&#39; does not exist.<br>Scoped package detected, looking in &#39;langchain__core/prompts&#39;<br>Loading module &#39;@langchain/core/prompts&#39; from &#39;node_modules&#39; folder, target file types: JavaScript, JSON.<br>Searching all ancestor node_modules directories for fallback extensions: JavaScript, JSON.<br>File &#39;/Users/davydewaele/Projects/AgenticAI/langchain-debugging/langchainjs/langchain-core/package.json&#39; exists according to earlier cached lookups.<br>File &#39;/Users/davydewaele/Projects/AgenticAI/langchain-debugging/langchainjs/langchain-core/prompts.js&#39; does not exist.<br>File &#39;/Users/davydewaele/Projects/AgenticAI/langchain-debugging/langchainjs/langchain-core/prompts.jsx&#39; does not exist.<br>Resolution of non-relative name failed; trying with &#39;--moduleResolution bundler&#39; to see if project may need configuration update.<br>Loading module &#39;@langchain/core/prompts&#39; from &#39;node_modules&#39; folder, target file types: TypeScript, Declaration.<br>Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.<br>File &#39;/Users/davydewaele/Projects/AgenticAI/langchain-debugging/langchainjs/langchain-core/package.json&#39; exists according to earlier cached lookups.<br>Entering conditional exports.<br>Matched &#39;exports&#39; condition &#39;types&#39;.<br>Entering conditional exports.<br>Matched &#39;exports&#39; condition &#39;import&#39;.<br>Using &#39;exports&#39; subpath &#39;./prompts&#39; with target &#39;./prompts.d.ts&#39;.<br>File &#39;/Users/davydewaele/Projects/AgenticAI/langchain-debugging/langchainjs/langchain-core/prompts.d.ts&#39; does not exist.<br>Failed to resolve under condition &#39;import&#39;.<br>Saw non-matching condition &#39;require&#39;.<br>Matched &#39;exports&#39; condition &#39;default&#39;.<br>Using &#39;exports&#39; subpath &#39;./prompts&#39; with target &#39;./prompts.d.ts&#39;.<br>File &#39;/Users/davydewaele/Projects/AgenticAI/langchain-debugging/langchainjs/langchain-core/prompts.d.ts&#39; does not exist.<br>Failed to resolve under condition &#39;default&#39;.<br>Exiting conditional exports.<br>Failed to resolve under condition &#39;types&#39;.<br>Matched &#39;exports&#39; condition &#39;import&#39;.<br>Using &#39;exports&#39; subpath &#39;./prompts&#39; with target &#39;./prompts.js&#39;.<br>File name &#39;/Users/davydewaele/Projects/AgenticAI/langchain-debugging/langchainjs/langchain-core/prompts.js&#39; has a &#39;.js&#39; extension - stripping it.<br>File &#39;/Users/davydewaele/Projects/AgenticAI/langchain-debugging/langchainjs/langchain-core/prompts.ts&#39; does not exist.<br>File &#39;/Users/davydewaele/Projects/AgenticAI/langchain-debugging/langchainjs/langchain-core/prompts.tsx&#39; does not exist.<br>File &#39;/Users/davydewaele/Projects/AgenticAI/langchain-debugging/langchainjs/langchain-core/prompts.d.ts&#39; does not exist.<br>Failed to resolve under condition &#39;import&#39;.<br>Saw non-matching condition &#39;require&#39;.<br>Exiting conditional exports.<br>Export specifier &#39;./prompts&#39; does not exist in package.json scope at path &#39;/Users/davydewaele/Projects/AgenticAI/langchain-debugging/langchainjs/langchain-core&#39;.<br>Scoped package detected, looking in &#39;langchain__core/prompts&#39;<br>======== Module name &#39;@langchain/core/prompts&#39; was not resolved. ========</pre><p>The module <a href="http://twitter.com/langchain/core">langchain/core</a>/prompts could not be resolved because</p><ul><li>There is no file like prompts.ts, prompts.d.ts, or prompts.js at the expected location.</li><li>The package’s package.json exports map defines ./prompts, but the corresponding file is missing.</li><li>Your current moduleResolution setting (Node10) does not support resolving subpaths via exports correctly in this setup.</li></ul><p>So it was looking for</p><ul><li>langchain-core/prompts.ts</li><li>langchain-core/prompts.d.ts</li><li>langchain-core/prompts.js</li></ul><p>But all of them are <strong>missing</strong>.</p><p>And indeed because we used a portal dependency and added the sources, we do not have these files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6VmgM3um0E5uH0SUtUe2_g.png" /></figure><p>Now there are 2 ways to get this to work</p><ol><li>Modify the package.json of langchain-core and have your mainand exportspoint to the typescript sources instead of the compiled javascript sources</li><li>Build the langchain-core project with sourceMap <em>(and modify the package.json to point to the compiled javascript files if needed)</em></li></ol><p>Lets explore these 2 options.</p><h4>Option 1 Modify the package.json to point to TypeScript sources</h4><p>The route you want to take here depends on the complexity of the dependent project. In this case, LangChainJS has an elaborate (custom) build script that will manipulate the output in such a way that it becomes very difficult to use option 1.</p><p>Option 1 assumes that you have a relatively simple package.json with a limited amount of entrypoints into your code. This is not the case with a big framework like LangChain.JS</p><p>The reason we are getting this error when attempting to run our code</p><pre>Source path: /Users/davydewaele/Projects/AgenticAI/langchain-debugging/myproject/src/tools.<br>Not found: /Users/davydewaele/Projects/AgenticAI/langchain-debugging/myproject/src/tools.</pre><p>is because in the package.json of LangChainJS we have this export definition</p><pre>&quot;exports&quot;: {<br>...<br>    &quot;./prompts&quot;: {<br>      &quot;types&quot;: {<br>        &quot;import&quot;: &quot;./prompts.d.ts&quot;,<br>        &quot;require&quot;: &quot;./prompts.d.cts&quot;,<br>        &quot;default&quot;: &quot;./prompts.d.ts&quot;<br>      },<br>      &quot;import&quot;: &quot;./prompts.js&quot;,<br>      &quot;require&quot;: &quot;./prompts.cjs&quot;<br>    },<br>...<br>}</pre><p>What this is telling NodeJS / TypeScript is “<em>“If someone imports @langchain/core/prompts, serve them prompts.js and prompts.d.ts. ”</em></p><p>If we would change that to our actual typescript source (you will need to know what typescript file to look for in the sources)</p><pre>    &quot;./prompts&quot;: {<br>      &quot;import&quot;: &quot;./src/prompts/index.ts&quot;<br>    },</pre><p>You will be able to get it working.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s90cPqJ7-FXOw1Po8pgEGQ.png" /></figure><p>however you might still run into other issues, as your editor will most likely no longer be able to resolve modules</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0I4pLBwDkSkii00KqSOn4w.png" /></figure><p>For this to work you might need to change the <strong>moduleResolution</strong> to “bundler” in your tsconfig.json</p><p>So as you can already tell this is beginning to get very messy. A project like <strong>LangChain.JS</strong> also contains lots of export definitions so it would require a lot of changes in this package.json</p><pre>&quot;exports&quot;: {<br>    &quot;./agents&quot;: {<br>      &quot;types&quot;: {<br>        &quot;import&quot;: &quot;./agents.d.ts&quot;,<br>        &quot;require&quot;: &quot;./agents.d.cts&quot;,<br>        &quot;default&quot;: &quot;./agents.d.ts&quot;<br>      },<br>      &quot;import&quot;: &quot;./agents.js&quot;,<br>      &quot;require&quot;: &quot;./agents.cjs&quot;<br>    },<br>    &quot;./caches&quot;: {<br>      &quot;types&quot;: {<br>        &quot;import&quot;: &quot;./caches.d.ts&quot;,<br>        &quot;require&quot;: &quot;./caches.d.cts&quot;,<br>        &quot;default&quot;: &quot;./caches.d.ts&quot;<br>      },<br>      &quot;import&quot;: &quot;./caches.js&quot;,<br>      &quot;require&quot;: &quot;./caches.cjs&quot;<br>    },<br>    &quot;./callbacks/base&quot;: {<br>      &quot;types&quot;: {<br>        &quot;import&quot;: &quot;./callbacks/base.d.ts&quot;,<br>        &quot;require&quot;: &quot;./callbacks/base.d.cts&quot;,<br>        &quot;default&quot;: &quot;./callbacks/base.d.ts&quot;<br>      },<br>      &quot;import&quot;: &quot;./callbacks/base.js&quot;,<br>      &quot;require&quot;: &quot;./callbacks/base.cjs&quot;<br>    },<br>    &quot;./callbacks/dispatch&quot;: {<br>      &quot;types&quot;: {<br>        &quot;import&quot;: &quot;./callbacks/dispatch.d.ts&quot;,<br>        &quot;require&quot;: &quot;./callbacks/dispatch.d.cts&quot;,<br>        &quot;default&quot;: &quot;./callbacks/dispatch.d.ts&quot;<br>      },<br>      &quot;import&quot;: &quot;./callbacks/dispatch.js&quot;,<br>      &quot;require&quot;: &quot;./callbacks/dispatch.cjs&quot;<br>    },<br>.....</pre><p>So all of these would need to be changed.</p><p>This brings us to option 2</p><h4>Option 2 : Build the LangChainJS project with sourceMaps</h4><p>In order to build the langchain-core module we simply need to</p><ul><li>go in the langchain-core folder</li><li>modify the tsconfig.json to include ”sourceMap”: true</li><li>run a yarn install and yarn build</li></ul><pre>base ❯ yarn install<br>....<br>➤ YN0002: │ release-it@npm:18.1.2 doesn&#39;t provide @types/node (p3e815), requested by inquirer<br>➤ YN0000: │ Some peer dependencies are incorrectly met; run yarn explain peer-requirements &lt;hash&gt; for details, where &lt;hash&gt; is the six-letter p-prefixed code<br>➤ YN0000: └ Completed in 0s 368ms<br>➤ YN0000: ┌ Fetch step<br>➤ YN0000: └ Completed in 0s 493ms<br>➤ YN0000: ┌ Link step<br>➤ YN0000: └ Completed in 0s 777ms<br>➤ YN0000: Done with warnings in 1s 888ms<br><br>base ❯ yarn build<br>╭──────────────────────────────────────────────────────────────────────────╮<br>│                                                                          │<br>│                     Update available v2.5.4 ≫ v2.5.5                     │<br>│    Changelog: https://github.com/vercel/turborepo/releases/tag/v2.5.5    │<br>│          Run &quot;yarn dlx @turbo/codemod@latest update&quot; to update           │<br>│                                                                          │<br>│          Follow @turborepo for updates: https://x.com/turborepo          │<br>╰──────────────────────────────────────────────────────────────────────────╯<br>turbo 2.5.4<br><br>• Packages in scope: @langchain/core<br>• Running build:internal in 1 packages<br>• Remote caching disabled<br>@langchain/scripts:build:internal: cache hit (outputs already on disk), replaying logs 3dd01732c1648a51<br>@langchain/scripts:build:internal:<br>@langchain/scripts:build:internal: Tree shaking checks passed!<br>@langchain/core:build:internal: cache miss, executing 94bd577ada6c52c5<br>@langchain/core:build:internal:<br>@langchain/core:build:internal: Tree shaking checks passed!<br><br> Tasks:    2 successful, 2 total<br>Cached:    1 cached, 2 total<br>  Time:    8.463s</pre><p>Once that is done you should find that sourcemaps have been generated for the compiled javascripts. This will allow your IDE to find the TypeScript code associated with the compiled JavaScript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a11B8ZMoVA8gXcL7ZXYimw.png" /></figure><p>That WebStorm IDE will now be navigate to directly to the TypeScript files</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*58CGnBNvloO-6nAVnb3c_w.png" /></figure><p>and you will be able to put breakpoints in these typescript files and debug them</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xg2nCKq_29GAED8h6l3pow.png" /></figure><p>Occasionaly you might get this exclamation mark in WebStorm. Sometimes it can get confused, especially if remove folders, or do lots of yarn commands. Restarting WebStorm usually fixes it, as it will reload your project again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1FE0ojFAU5uiy0dNUzYi-g.png" /></figure><h3>Conclusion</h3><p>TypeScript and TypeScript debugging can be a bit overwhelming. Not only do you need to have a deep enough level of understanding of how TypeScript / JavaScript works, but you also need to know how Package Managers like Yarn will download / store and reference your dependencies. You need to know how projects get compiled (tsc) and run (tsx) <br>And finally also need to know how your IDE will interact with all of these tools in order to have a pleasant development and debugging experience.</p><p>Hopefully this post was able to clear things up a bit !</p><p>Happy developping ….</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ef500af4cf4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TypeScript Frustration TSFR-001 : Yarn 4 / PnP and dependency resolution]]></title>
            <link>https://medium.com/@ddewaele/typescript-frustration-tsfr-001-yarn-4-pnp-and-dependency-resolution-fb76be881842?source=rss-9ac28ff4a11b------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb76be881842</guid>
            <dc:creator><![CDATA[Davy De Waele]]></dc:creator>
            <pubDate>Sun, 03 Aug 2025 17:01:42 GMT</pubDate>
            <atom:updated>2025-08-06T05:31:40.619Z</atom:updated>
            <content:encoded><![CDATA[<h3>TypeScript Frustration TSFR-001 : Yarn 4 / PnP and dependency resolution</h3><p>I’ve decided to write-up a weekly report of all the frustrating things I encounter with the JavaScript / TypeScript eco-system.</p><p>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.</p><p>I will try to describe the issue as best as I can and when possible also describe the solution.</p><p>I think it’s a good way to get a more fundamental understanding on how things work and hopefully it will help others.</p><p>So …. without further ado, here’s the frustration of the day : <strong>TS2307: Cannot find module x or its corresponding type declarations </strong>when using Yarn4 and PnP</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B4dqQBpiD5gue4aVYPx3EQ.png" /></figure><h3>The issue</h3><blockquote>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 tails during compilation , and my code editor is also showing errors. (TS2307: Cannot find module .. or its corresponding type declarations.)</blockquote><h3>The context</h3><blockquote>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</blockquote><h3>The solution (for those that are in a hurry)</h3><blockquote>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.</blockquote><h3>The project</h3><p>I have a project with the following typescript source. It features a single import from the @langchain/core module</p><pre>import { ChatPromptTemplate } from &quot;@langchain/core/prompts&quot;;<br><br>const prompt = ChatPromptTemplate.fromTemplate(<br>    `Answer the following question to the best of your ability:\n{question}`<br>);<br><br>console.log(await prompt.format({ question: &quot;What is the answer to life, the universe, and everything?&quot; }));</pre><h3>The yarn package manager</h3><p>I had bootstrapped the project with yarn (notice how it defaults to 4.3.1 — more on that later).</p><pre>yarn init -y<br>➤ YN0000: · Yarn 4.3.1<br>➤ YN0000: ┌ Resolution step<br>➤ YN0000: └ Completed<br>➤ YN0000: ┌ Fetch step<br>➤ YN0000: └ Completed<br>➤ YN0000: ┌ Link step<br>➤ YN0000: └ Completed<br>➤ YN0000: · Done in 0s 20ms</pre><h3>The @langchain/core dependency</h3><p>I have installed the @langchain/core dependency with yarn</p><pre> yarn add @langchain/core<br>➤ YN0000: ┌ Resolution step<br>➤ YN0000: └ Completed<br>➤ YN0000: ┌ Fetch step<br>➤ YN0013: │ @langchain/core@npm:0.3.66 can&#39;t be found in the cache and will be fetched from the remote registry<br>➤ YN0000: └ Completed<br>➤ YN0000: ┌ Link step<br>➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental<br>➤ YN0000: └ Completed<br>➤ YN0000: Done with warnings in 0s 215ms</pre><p>I also added the tsx and typescript dependencies</p><pre>yarn add -D typescript<br>yarn add -D tsx</pre><p>My package.json looks fine</p><pre>{<br>  &quot;name&quot;: &quot;myproject&quot;,<br>  &quot;packageManager&quot;: &quot;yarn@4.3.1&quot;,<br>  &quot;type&quot;: &quot;module&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;tsx&quot;: &quot;tsx&quot;<br>  },<br>  &quot;dependencies&quot;: {<br>    &quot;@langchain/core&quot;: &quot;^0.3.66&quot;<br>  },<br>  &quot;devDependencies&quot;: {<br>    &quot;tsx&quot;: &quot;^4.20.3&quot;,<br>    &quot;typescript&quot;: &quot;^5.9.2&quot;<br>  }<br>}</pre><h3>Running via tsx / IDE</h3><p>I can run theTypeScriptfile just fine from the command line using tsx</p><pre>yarn run tsx src/index.ts<br>Human: Answer the following question to the best of your ability:<br>What is the answer to life, the universe, and everything?</pre><p>I can run it fine from my IDE</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oRScbr5pQbsENFWGwbYd8Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*bP-WftUPdDCFnwxhCAbBOA.png" /></figure><h3>TypeScript errors in IDE and TSC</h3><p>But when I look at the sources in my IDE it keeps saying</p><blockquote>TS2307: Cannot find module <a href="http://twitter.com/langchain/core">@langchain/core</a>/prompts or its corresponding type declarations.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D5qPKuNLG_kQlzIAsQv_eA.png" /></figure><p>This also doesn’t seem to be a WebStorm issue as issuing the tsc command on the command line results in a similar error</p><pre>yarn tsc<br>src/index.ts:1:36 - error TS2307: Cannot find module &#39;@langchain/core/prompts&#39; or its corresponding type declarations.</pre><p>So why is that ?</p><p>It is weird as you can see that it has picked up the @langchain/core as an external dependency, and it should be able to resolve the @langchain/core/prompts import</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*1-hETN_8WY7gKl2ovwkHRA.png" /></figure><p>And ifI do a reveal in finder I can see that it resolves the dependency from the following file</p><p><strong>~/.yarn/berry/cache/@langchain-core-npm-0.3.66-d2b05db5ca-10c0.zip</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*DH6aC9j6SbwBaHJj2YO2-w.png" /></figure><p>and indeed inside that zip file we have the correct path</p><h3>The issue ?</h3><p>So it appears that tsc is not working when 4.3.1 is used as the package manager</p><pre><br>base ❯ yarn install<br>➤ YN0000: · Yarn 4.3.1<br>➤ YN0000: ┌ Resolution step<br>➤ YN0085: │ + typescript@patch:typescript@npm%3A5.9.2#optional!builtin&lt;compat/typescript&gt;::version=5.9.2&amp;hash=379a07<br>➤ YN0085: │ - typescript@patch:typescript@npm%3A5.9.2#optional!builtin&lt;compat/typescript&gt;::version=5.9.2&amp;hash=cef18b<br>➤ YN0000: └ Completed<br>➤ YN0000: ┌ Fetch step<br>➤ YN0000: └ Completed<br>➤ YN0000: ┌ Link step<br>➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental<br>➤ YN0000: └ Completed<br>➤ YN0000: · Done with warnings in 0s 146ms<br><br>~/Projects/AgenticAI/typescript-debug-langchainjs-yarn-portal3/myproject master*<br>base ❯ yarn tsc<br>src/index.ts:1:36 - error TS2307: Cannot find module &#39;@langchain/core/prompts&#39; or its corresponding type declarations.<br><br>1 import { ChatPromptTemplate } from &quot;@langchain/core/prompts&quot;;<br>                                     ~~~~~~~~~~~~~~~~~~~~~~~~~<br><br><br>Found 1 error in src/index.ts:1<br></pre><p>Upgrading to 4.5.2 fixes the issue</p><pre>base ❯ yarn install<br>➤ YN0000: · Yarn 4.5.2<br>➤ YN0000: ┌ Resolution step<br>➤ YN0085: │ + typescript@patch:typescript@npm%3A5.9.2#optional!builtin&lt;compat/typescript&gt;::version=5.9.2&amp;hash=5786d5<br>➤ YN0085: │ - typescript@patch:typescript@npm%3A5.9.2#optional!builtin&lt;compat/typescript&gt;::version=5.9.2&amp;hash=379a07<br>➤ YN0000: └ Completed<br>➤ YN0000: ┌ Fetch step<br>➤ YN0000: └ Completed<br>➤ YN0000: ┌ Link step<br>➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental<br>➤ YN0000: └ Completed<br>➤ YN0000: · Done with warnings in 0s 148ms<br><br>~/Projects/AgenticAI/typescript-debug-langchainjs-yarn-portal3/myproject master*<br>base ❯ yarn tsc</pre><p>When doing a yarn tsc — traceResolution you can indeed see that with 4.5.2 it is resolving the dependency via the berry cache (PnP)</p><pre>base ❯ yarn tsc --traceResolution<br>======== Resolving module &#39;@langchain/core/prompts&#39; from &#39;/Users/davydewaele/Projects/AgenticAI/typescript-debug-langchainjs-yarn-portal2/myproject/src/index.ts&#39;. ========<br>Explicitly specified module resolution kind: &#39;Node10&#39;.<br>Loading module &#39;@langchain/core/prompts&#39; from &#39;node_modules&#39; folder, target file types: TypeScript, Declaration.<br>Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.<br>Found &#39;package.json&#39; at &#39;/Users/davydewaele/.yarn/berry/cache/@langchain-core-npm-0.3.66-d2b05db5ca-10c0.zip/node_modules/@langchain/core/package.json&#39;.<br>&#39;package.json&#39; does not have a &#39;typesVersions&#39; field.<br>File &#39;/Users/davydewaele/.yarn/berry/cache/@langchain-core-npm-0.3.66-d2b05db5ca-10c0.zip/node_modules/@langchain/core/prompts.ts&#39; does not exist.<br>File &#39;/Users/davydewaele/.yarn/berry/cache/@langchain-core-npm-0.3.66-d2b05db5ca-10c0.zip/node_modules/@langchain/core/prompts.tsx&#39; does not exist.<br>File &#39;/Users/davydewaele/.yarn/berry/cache/@langchain-core-npm-0.3.66-d2b05db5ca-10c0.zip/node_modules/@langchain/core/prompts.d.ts&#39; exists - use it as a name resolution result.<br>&#39;package.json&#39; does not have a &#39;peerDependencies&#39; field.<br>Resolving real path for &#39;/Users/davydewaele/.yarn/berry/cache/@langchain-core-npm-0.3.66-d2b05db5ca-10c0.zip/node_modules/@langchain/core/prompts.d.ts&#39;, result &#39;/Users/davydewaele/.yarn/berry/cache/@langchain-core-npm-0.3.66-d2b05db5ca-10c0.zip/node_modules/@langchain/core/prompts.d.ts&#39;.<br>======== Module name &#39;@langchain/core/prompts&#39; was successfully resolved to &#39;/Users/davydewaele/.yarn/berry/cache/@langchain-core-npm-0.3.66-d2b05db5ca-10c0.zip/node_modules/@langchain/core/prompts.d.ts&#39; with Package ID &#39;@langchain/core/prompts.d.ts@0.3.66&#39;. ========</pre><p>When doing a yarn tsc — traceResolution you can indeed see that with 4.5.1 it is resolving trying to resolve the dependency via node_modules</p><pre>base ❯ yarn tsc --traceResolution<br>======== Resolving module &#39;@langchain/core/prompts&#39; from &#39;/Users/davydewaele/Projects/AgenticAI/typescript-debug-langchainjs-yarn-portal3/myproject/src/index.ts&#39;. ========<br>Explicitly specified module resolution kind: &#39;Node10&#39;.<br>Loading module &#39;@langchain/core/prompts&#39; from &#39;node_modules&#39; folder, target file types: TypeScript, Declaration.<br>Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.<br>Directory &#39;/Users/davydewaele/Projects/AgenticAI/typescript-debug-langchainjs-yarn-portal3/myproject/src/node_modules&#39; does not exist, skipping all lookups in it.<br>Scoped package detected, looking in &#39;langchain__core/prompts&#39;<br>Directory &#39;/Users/davydewaele/Projects/AgenticAI/typescript-debug-langchainjs-yarn-portal3/myproject/node_modules&#39; does not exist, skipping all lookups in it.<br>Scoped package detected, looking in &#39;langchain__core/prompts&#39;<br>Directory &#39;/Users/davydewaele/Projects/AgenticAI/typescript-debug-langchainjs-yarn-portal3/node_modules&#39; does not exist, skipping all lookups in it.<br>Scoped package detected, looking in &#39;langchain__core/prompts&#39;<br>Directory &#39;/Users/davydewaele/Projects/AgenticAI/node_modules&#39; does not exist, skipping all lookups in it.<br>Scoped package detected, looking in &#39;langchain__core/prompts&#39;<br>Directory &#39;/Users/davydewaele/Projects/node_modules&#39; does not exist, skipping all lookups in it.<br>Scoped package detected, looking in &#39;langchain__core/prompts&#39;<br>Directory &#39;/Users/davydewaele/node_modules&#39; does not exist, skipping all lookups in it.<br>Scoped package detected, looking in &#39;langchain__core/prompts&#39;<br>Directory &#39;/Users/node_modules&#39; does not exist, skipping all lookups in it.<br>Scoped package detected, looking in &#39;langchain__core/prompts&#39;<br>Directory &#39;/node_modules&#39; does not exist, skipping all lookups in it.<br>Scoped package detected, looking in &#39;langchain__core/prompts&#39;<br>Loading module &#39;@langchain/core/prompts&#39; from &#39;node_modules&#39; folder, target file types: JavaScript, JSON.<br>Searching all ancestor node_modules directories for fallback extensions: JavaScript, JSON.<br>Directory &#39;/Users/davydewaele/Projects/AgenticAI/typescript-debug-langchainjs-yarn-portal3/myproject/src/node_modules&#39; does not exist, skipping all lookups in it.<br>Directory &#39;/Users/davydewaele/Projects/AgenticAI/typescript-debug-langchainjs-yarn-portal3/myproject/node_modules&#39; does not exist, skipping all lookups in it.<br>Directory &#39;/Users/davydewaele/Projects/AgenticAI/typescript-debug-langchainjs-yarn-portal3/node_modules&#39; does not exist, skipping all lookups in it.<br>Directory &#39;/Users/davydewaele/Projects/AgenticAI/node_modules&#39; does not exist, skipping all lookups in it.<br>Directory &#39;/Users/davydewaele/Projects/node_modules&#39; does not exist, skipping all lookups in it.<br>Directory &#39;/Users/davydewaele/node_modules&#39; does not exist, skipping all lookups in it.<br>Directory &#39;/Users/node_modules&#39; does not exist, skipping all lookups in it.<br>Directory &#39;/node_modules&#39; does not exist, skipping all lookups in it.<br>======== Module name &#39;@langchain/core/prompts&#39; was not resolved. ========</pre><p>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</p><pre>base ❯ node index.js<br>node:internal/modules/esm/resolve:854<br>  throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), null);<br>        ^<br><br>Error [ERR_MODULE_NOT_FOUND]: Cannot find package &#39;@langchain/core&#39; imported from /Users/davydewaele/Projects/AgenticAI/typescript-debug-langchainjs-yarn-portal3/myproject/dist/index.js<br>    at packageResolve (node:internal/modules/esm/resolve:854:9)<br>    at moduleResolve (node:internal/modules/esm/resolve:927:18)<br>    at defaultResolve (node:internal/modules/esm/resolve:1169:11)<br>    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:540:12)<br>    at ModuleLoader.resolve (node:internal/modules/esm/loader:509:25)<br>    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:239:38)<br>    at ModuleWrap.&lt;anonymous&gt; (node:internal/modules/esm/module_job:96:40)<br>    at link (node:internal/modules/esm/module_job:95:36) {<br>  code: &#39;ERR_MODULE_NOT_FOUND&#39;<br>}<br><br>Node.js v20.17.0<br></pre><p>If you bootstrap node using yarn it will work</p><pre>base ❯ yarn node index.js<br>Human: Answer the following question to the best of your ability:<br>What is the answer to life, the universe, and everything?</pre><p>this is because here yarn will inject your <strong>.pnp.cjs</strong> loader into node, allowing node to resolve your packages via PnP.</p><h3>Things I’ve learned along the way</h3><ul><li>Package managers matter. I never noticed the packageManager field in package.json or used CorePack to install a package manager.</li><li>I didn’t know what CorePack was</li><li>Didn’t realize there such a thing as Yarn Classic (v1) using node_modules, and Yarn v2 / v3 / v4 using PnP</li><li>I didn’t know you need to use yarn to bootstrap node if you are working in PnP environment</li><li>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.</li></ul><h3>Conclusion</h3><p>Latest versions of Yarn and PnP introduce a totally new way of resolving node modules. There is no node_modules 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 node_modules , something it shouldn’t do when using PnP.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb76be881842" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cognito CDK Hell]]></title>
            <link>https://medium.com/@ddewaele/cognito-cdk-hell-94cefb324129?source=rss-9ac28ff4a11b------2</link>
            <guid isPermaLink="false">https://medium.com/p/94cefb324129</guid>
            <category><![CDATA[cognito]]></category>
            <category><![CDATA[cdk]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Davy De Waele]]></dc:creator>
            <pubDate>Thu, 17 Oct 2024 15:47:49 GMT</pubDate>
            <atom:updated>2024-10-17T15:47:49.179Z</atom:updated>
            <content:encoded><![CDATA[<p>Today I spent the bigger part of the day struggling with Cognito and AWS CDK.</p><p>Here’s the requirement what triggered our slow slope into chaos, madness and frustration</p><blockquote>Update an existing UserPool in our CloudFormation stack so that it now has 2 required attributes (firstname and givenName)</blockquote><p>Now granted, in the AWS Console we do get a hint that this can only be done <em>when creating a user pool</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C4psS8m0dAZ-1lHY23W5Yg.png" /></figure><p>Unfortunately we already have an existing User Pool, and trying to add these required attributes through our CDK code like this</p><pre>this.userPool = new UserPool(this, &#39;UserPool&#39;, {<br>  standardAttributes: {<br>    givenName: {<br>      required: true,<br>      mutable: true,<br>    },<br>    familyName: {<br>      required: true,<br>      mutable: true,<br>    },<br>  },<br>});</pre><p>results in a somewhat obscure error message</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w019GvpEiCY4fes4Q0Fz7g.png" /></figure><pre>Resource handler returned message: <br>&quot;Invalid AttributeDataType input, consider using the provided <br>AttributeDataType enum. <br>(Service: CognitoIdentityProvider, Status Code: 400, <br>Request ID: f4b198d9-3b9d-4233-83b4-5ffe6dd3003b)&quot; </pre><blockquote><strong>Issue nr 1 </strong>: updating an existing UserPool to have 2 required attributes is not possible, a very obscure error message is returned by CloudFormation.</blockquote><p>But ok. Fair enough … It seems like we’ll need to create a new UserPool.</p><p>Lets see what happens when we try to replace our old Cognito User Pool with a new one by changing its name.</p><pre>    this.userPool = new UserPool(this, &#39;UserPoolUpdated&#39;, {<br>      standardAttributes: {<br>        givenName: {<br>          required: true,<br>          mutable: true,<br>        },<br>        familyName: {<br>          required: true,<br>          mutable: true,<br>        },<br>      },<br>    });</pre><p>This will trigger a Cognito user pool replacement when deploying this.</p><p>However, when attempting to do so we get the following error :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JmWWJhaf3YKLySLkht9npA.png" /></figure><p>As you can see we are informed about the fact that our cognito stack is exporting something (the userpool) to our other lambda stack</p><pre>Export cognitoStack:ExportsOutputRefUserPool6BA7E5F296FD7236 <br>cannot be deleted as it is in use by lambdaStack</pre><p>And indeed, the fact that we are passing our userPoolId in another stack via this snippet</p><pre>const cognitoStack = new CognitoStack(app, &#39;cognitoStack&#39;, {});<br>const lambdaStack = new LambdaStack(app, &#39;lambdaStack&#39;, {<br>  userPoolId: cognitoStack.userPool.userPoolId,<br>});</pre><p>Results in the CognitoStack creating an export (that is then imported by the lambda stack)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KOCTnSOMsuUQLjamZjvydA.png" /></figure><p>Hence we arrive at issue nr 2 (a generic annoying CDK issue with cross stack dependencies)</p><blockquote><strong>Issue nr 2</strong>: updating an existing UserPool causes AWS to replace it. During this replacement process if needs to remove the original one, meaning that the export value from that userpool will also get removed. This is not allowed as the export value is used elsewhere.</blockquote><p>As long as that export name is used somewhere (in our case it is used by our lambda stack), we cannot delete it.</p><p>And this is exactly what CDK is trying to do when it is “updating” our Cognito User Pool. Updating here means “replacing”. And “replacing” means “removing” and “creating”.</p><p>Now there is is a workaround for this “issue”.</p><p>We can add this horrible snippet in our code. This will programmatically create the exact same export (Satisfying the requirement that we cannot remove exports that are still used)</p><pre><br>new cdk.CfnOutput(cognitoStack, &quot;ExportsOutputRefUserPool6BA7E5F296FD7236&quot;, {<br>  value: &quot;eu-central-1_mxhWJoMmZ&quot;,<br>  exportName: &quot;cognitoStack:ExportsOutputRefUserPool6BA7E5F296FD7236&quot;,<br>});</pre><p>This will get rid of the previous error, but it will not introduce another error.</p><pre>Domain already associated with another user pool. <br>(Service: AWSCognitoIdentityProviderService; <br>Status Code: 400; Error Code: InvalidParameterException; <br>Request ID: 5ece4c0b-85ad-4c25-9039-e671ce0ae8c9; Proxy: null)</pre><p>Leading us to this Cognito specific quirck :</p><blockquote><strong>Issue nr 3</strong>: You cannot update a userpool while retaining its domain name. You will get the error saying “Domain already associated with another user pool”. This is confusing, as we just want to update an existing userpool, we don’t want to end up with 2 pools.</blockquote><p>This is confusing … so we’re updating our pool, but the CDK says that the domain is already associated with another user pool.</p><p>What is happening here … Well …</p><ul><li>We requested CDK to “update” our Cognito User Pool.</li><li>CDK first tries to create a new Cognito User Pool.</li><li>This fails because the domain associated with it still exists in our original Cognito User Pool.</li><li>During the rollback CDK will delete our newly created (but failed ) Cognito User Pool</li><li>This deletion is skipped because every Cognito User Pool has a default removal policy set to RETAIN .</li></ul><p>So you end up with a big mess basically</p><ul><li>Your Cognito User Pool is not updated</li><li>You do have a new (incomplete) Cognito User Pool sitting arround</li><li>Your original Cognito User Pool is also still around</li></ul><p>The only way to fix this is to temporarily remove the domain as you are doing the update</p><pre>    // this.userPool.addDomain(&quot;cognitoDomain&quot;, {<br>    //   cognitoDomain: {<br>    //     domainPrefix: &quot;cog-domain-cdk-hell&quot;<br>    //   }<br>    // })</pre><p>Because each UserPool has a Removal Policy set to RETAIN you will also end up with a bunch of UserPool that you will need to delete manually</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i3DCfxbJe2MOlcS5biX4Vg.png" /></figure><h3>Conclusion</h3><p>Even for a more experience AWS engineer, these errors can come accross as very confusing.</p><p>This ended costing us about 3 hours to get our heads around everything that was happening, all thanks to the obscure CloudFormation errors and the Cognito specific stuff that is going on.</p><p>Not only do you need to wrap your head around obscure error messages, understand what CDK is trying to do under the hood, and find workarounds to get around these errors, this is really distracting and you end up loosing a lot of time.</p><p>Now on a dev environment this is all fine, where you probably have elevated rights to do things (like performing cdk deploys locally), but if you want to roll this out in an official way, through proper staging pipelines in a CICD environment this becomes really problematic.</p><p>You would need to orchestrate multiple intermediate pipeline runs</p><ul><li>replacing the cognito user pool without a domain name + setting up the fake export names</li><li>putting the domain name back on the user pool</li><li>migrating your users</li></ul><p>If you want to go through this world of pain yourself, checkout this repo : <a href="https://github.com/ddewaele/cdk-cognito-hell">https://github.com/ddewaele/cdk-cognito-hell</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94cefb324129" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[API Gateway / Nest JS woes]]></title>
            <link>https://medium.com/@ddewaele/api-gateway-nest-js-woes-59b585d846a3?source=rss-9ac28ff4a11b------2</link>
            <guid isPermaLink="false">https://medium.com/p/59b585d846a3</guid>
            <dc:creator><![CDATA[Davy De Waele]]></dc:creator>
            <pubDate>Thu, 29 Aug 2024 19:52:40 GMT</pubDate>
            <atom:updated>2024-08-29T19:52:40.922Z</atom:updated>
            <content:encoded><![CDATA[<p>I just spent the entire day debugging an issue with AWS API Gateway and NestJS. In all honesty it was last month when I spent the entire day debugging an issue. This has been sitting in my drafts for too long.</p><p>I thought a quick write-up might be in order.</p><p>We have a requirement where we are deploying an NestJS app with both a public part and a private part. We are running our NestJS backend as a lambda, sitting behind an API Gateway using <a href="https://www.npmjs.com/package/@codegenie/serverless-express">@codegenie/serverless-express</a> in order to expose our NestJS application as a Lambda.</p><p>The serverless-express library is needed in order for our NestJs app to interpret / translate the events that API Gateway pushes to the lambda.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j52mmp-l53O2vwBlmVhvmw.png" /></figure><p>All security aspects are off-loaded to the API GW, as ultimately it will be API Gateway that will provide a requestContext that contains either</p><ul><li>A cognito identity</li><li>An API key.</li></ul><p>That’s the beauty of the solution. There is no need check API keys programmatically or decode and verify JWT tokens. All of this has already been done by the API Gateway. Only valid , verified requests will be able to hit our NestJS backend.</p><p>The only requirement is that you have dedicated resources on your API Gateway so that you put the appropriate authorizer on them. So by definition, the fact that you want a public and a protected part means that you will need to setup 2 resources.</p><p>So for our private / public requirement we have decided to expose the following paths.</p><ul><li>/api/* = our main API , protected by a Cognito authorizer or API key</li><li>/openapi/* = our documentation, should be public</li></ul><p>Now there are several ways to configure this on API Gateway. Remember that API Gateway is built on <strong>resources</strong>. A resource represents a path that will be invoked on your API Gateway.</p><p><strong>Option 1:</strong></p><ul><li>Create a resource with a top level greedy path /api/{proxy+} and protect it with a Cognito Authorizer or API key</li><li>Create another top level greedy path/openapi/{proxy+} resource for the public path</li></ul><p><strong>Option 2:</strong></p><ul><li>Create a resource with a top level greedy path /{proxy+} (acting as a catch-all) and protect it with a Cognito Authorizer or API key</li><li>Create another top level greedy path/openapi/{proxy+} resource for the public path. This is more strict than the catch-all, so everything starting with /openapi will be matched with this one.</li></ul><p>You might think that both options would be valid as it would allow us to have 2 separate resources on API Gateway. A requirement if you want to have a public and a private part.</p><p>We already had a /api/{proxy+} mapping in place so we went for option 1.</p><p>Now the way that API Gateway works is that when a request comes in it will generate an event to our Lambda that among a lot of other things contains this :</p><pre>&quot;resource&quot;: &quot;/api/{proxy+}&quot;,<br>&quot;path&quot;: &quot;/api/products/123&quot;,<br>&quot;pathParameters&quot;: {<br>  &quot;proxy&quot;: &quot;products/123&quot;<br>},<br>&quot;requestContext&quot;: {<br>  &quot;resourcePath&quot;: &quot;/api/{proxy+}&quot;,<br>  &quot;path&quot;: &quot;/prod/api/products/123&quot;,<br>}</pre><p>This is all the resource / path / proxy information that is in the API Gateway event.</p><p>What we can derive from this event is</p><ul><li>our /api/{proxy+} resource is hit on the API Gateway. Now remember this is an <strong>API Gateway resource</strong>. It is not the actual path that is used.</li><li>The real path that was used here is /api/products/123 , and <strong>it was matched</strong> with the resource /api/{proxy+}</li></ul><p>/api/products/123 is something that NestJS <strong>cannot handle</strong> as</p><ul><li>NestJS only has a /products controller (no api prefix)</li><li>We do not have a <strong>global prefix</strong> defined in NestJS for /api</li></ul><p><a href="https://www.npmjs.com/package/@codegenie/serverless-express">@codegenie/serverless-express</a> will pass pathParameters.proxy to our NestJS app and that’s the mechanism that makes it work</p><p>In this case it is important to realise that</p><ul><li><a href="https://www.npmjs.com/package/@codegenie/serverless-express">@codegenie/serverless-express</a> is responsible for translating the API Gateway event to something that can be processed by NestJS</li><li>Our NestJS will only see products/123 coming in as a request</li><li>Our NestJS will not see there was an /api prefix in the API Gateway request.</li></ul><p>Now lets take a look at what happens where we load up the documentation on /openapi/index.html</p><pre>&quot;resource&quot;: &quot;/openapi/{proxy+}&quot;,<br>&quot;path&quot;: &quot;/openapi/index.html&quot;,<br>&quot;pathParameters&quot;: {<br>  &quot;proxy&quot;: &quot;index.html&quot;<br>},<br>&quot;requestContext&quot;: {<br>  &quot;resourcePath&quot;: &quot;/api/{proxy+}&quot;,<br>  &quot;path&quot;: &quot;/prod/openapi/index.html&quot;,<br>}</pre><p>Again, important to realise that</p><ul><li>Our NestJS will see index.html coming in.</li><li>NestJS is unaware that this is the openapi resource and that this is the public section.</li></ul><p>This might seem good at first but has a disconcerning side-effect.</p><blockquote>Because it now becomes perfectly possible to execute a call like this /openapi/products/123.</blockquote><blockquote>As weird as this looks, this call will actually hit our backend NestJS products controller and NestJS will process /products/123</blockquote><blockquote>So calling /api/products/123 and/openapi/products/123 is equal as far as NestJS concerned. Simply because of the way <a href="https://www.npmjs.com/package/@codegenie/serverless-express">@codegenie/serverless-express</a> processes the API Gateway events, (only passing the {proxy+} ) is not ideal.</blockquote><p>So to mitigate the risk of somebody accessing our NestJS backend through this public /openapi path an API Gateway resource policy would be required to only allow access to /openapi/ and not /openapi/products</p><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Principal&quot;: &quot;*&quot;,<br>      &quot;Action&quot;: &quot;execute-api:Invoke&quot;,<br>      &quot;Resource&quot;: [<br>        &quot;arn:aws:execute-api:*:*:49f6svmcfe/*/GET/openapi/&quot;,<br>        &quot;arn:aws:execute-api:*:*:49f6svmcfe/*/GET/openapi/openapi/*&quot;<br>      ]<br>    },<br>    {<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Principal&quot;: &quot;*&quot;,<br>      &quot;Action&quot;: &quot;execute-api:Invoke&quot;,<br>      &quot;Resource&quot;: [<br>        &quot;arn:aws:execute-api:*:*:49f6svmcfe/*/GET/api&quot;,<br>        &quot;arn:aws:execute-api:*:*:49f6svmcfe/*/GET/api/*&quot;<br>      ]<br>    }<br>  ]<br>}</pre><h3>Conclusion</h3><p>So depending on how you setup your API GW resources, NestJS will see totally different incoming paths.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A3SrhfuTt5VfQ3KtOtkOmQ.png" /></figure><p>This is not only confusing, but it can also introduce serious security issues if you are using API Gateway resources to define public / private parts. Your NestJS will not have any context about the API Gateway resource that was hit, and it will only see the proxy part.</p><p>This IMHO is a flaw in the <a href="https://www.npmjs.com/package/@codegenie/serverless-express">@codegenie/serverless-express</a> library, there are some related open issues in the library as seen here : <a href="https://github.com/CodeGenieApp/serverless-express/issues/648">https://github.com/CodeGenieApp/serverless-express/issues/648</a></p><p>Hopefully this gets fixed soon.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59b585d846a3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying your NestJS app as a Lambda behind API Gateway]]></title>
            <link>https://medium.com/@ddewaele/deploying-your-nestjs-app-as-a-lambda-behind-api-gateway-cbf5e61a6199?source=rss-9ac28ff4a11b------2</link>
            <guid isPermaLink="false">https://medium.com/p/cbf5e61a6199</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[nestjs]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Davy De Waele]]></dc:creator>
            <pubDate>Mon, 18 Dec 2023 18:24:18 GMT</pubDate>
            <atom:updated>2023-12-18T18:24:18.881Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog post I would like to show you how to deploy your NestJS backend on AWS in a serverless way using API gateway and Lambda.</p><p>We’re going to be covering a few ways to do it, automate the process using AWS CDK (Cloud Development Kit), go through some errors I had with it, and round up with an architectural / philosophical discussion on whether this is a good approach.</p><p>For those interested in the code, feel free to check out the following repo containing not only the NestJS code, but also all of the CDK infrastructure as code.</p><p><a href="https://github.com/ddewaele/cdk-simple-lambda-nestjs">GitHub - ddewaele/cdk-simple-lambda-nestjs</a></p><p>This repo will allow you to deploy your NestJS backend as lambda, allowing HTTP requests to come in via API gateway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/0*k-QCbMWTS7jzVd5_.png" /></figure><h3>NestJS</h3><p>For those of you who don’t know NestJS, I highly recommend you checkout the <a href="https://nestjs.com/">https://nestjs.com/</a> website that contains lots of resources, guides and documentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/0*YiH-PDWZwEuhLJKR.jpeg" /></figure><p>NestJS refers to itself as <em>a progressive Node.js framework for building efficient, reliable and scalable server-side applications.</em></p><p>It‘s a great way to build backend applications on top of NodeJS, and coming from a Java / Spring Boot background it all came across as very familiar.</p><p>It features stuff like dependency injection / controllers / services / modules / ORM solutions / plugins / …. the works.</p><h3>Moving to serverless</h3><p>And it just so happens that we are in the process of migrating some of our more traditional Java based microservice backends into more serverless architectures based on NodeJS. So NestJS looks like a very good candidate.</p><p>Now NestJS doesn’t promote itself as a serverless solution. The main use-case is still you spin it up on some compute in the cloud, where it listens on an HTTP port for incoming requests.</p><pre>import { NestFactory } from &#39;@nestjs/core&#39;;<br>import { AppModule } from &#39;./app.module&#39;;<br><br>async function bootstrap() {<br>  const app = await NestFactory.create(AppModule);<br>  await app.listen(3000);<br>}<br>bootstrap();</pre><p>So being a NodeJS application, you can easily deploy it onto Vercel, Heroku or AWS (using something like AWS BeanStalk).</p><p>However, as we want run NestJS in a serverless setting, we will need to wrap or bootstrap NestJS in a Lambda handler for it to be truely serverless.</p><blockquote>And offcourse like most things in Javascript / NodeJS land : there is a library for that.</blockquote><h3>Serverless Express</h3><p>Meet <a href="https://www.npmjs.com/package/@vendia/serverless-express">@vendia/serverless-express</a>, a library that allows you to run serverless applications and REST APIs using your existing <a href="https://nodejs.org/">Node.js</a> application framework, on top of <a href="https://aws.amazon.com/lambda/">AWS Lambda</a> and <a href="https://aws.amazon.com/api-gateway/">Amazon API Gateway</a>.</p><p>Simply put, instead of bootstrapping NestJS like we did above, we’re now going to be using the following Lamba handler</p><pre>import { NestFactory } from &#39;@nestjs/core&#39;;<br>import { ExpressAdapter } from &#39;@nestjs/platform-express&#39;;<br>import serverlessExpress from &#39;@vendia/serverless-express&#39;;<br>import { Context, Handler } from &#39;aws-lambda&#39;;<br>import express from &#39;express&#39;;<br><br>import { AppModule } from &#39;./app.module&#39;;<br><br>let cachedServer: Handler;<br><br>async function bootstrap() {<br>  if (!cachedServer) {<br>    const expressApp = express();<br>    const nestApp = await NestFactory.create(<br>      AppModule,<br>      new ExpressAdapter(expressApp),<br>    );<br><br>    nestApp.enableCors();<br><br>    await nestApp.init();<br><br>    cachedServer = serverlessExpress({ app: expressApp });<br>  }<br><br>  return cachedServer;<br>}<br><br>export const handler = async (event: any, context: Context, callback: any) =&gt; {<br>  const server = await bootstrap();<br><br>  return server(event, context, callback);<br>};</pre><p>This is effectively your Lamba handler, enabling you to deploy your NestJS application as a Lambda.</p><p>And AWS CDK makes it very easy to create this Lambda function out of your codebase like this. (assuming the code snippet above is defined in a lambda.ts file</p><pre>const nestJsLambda = new lambda.Function(this, &#39;CustomerCrudLambda&#39;, {<br>  runtime: lambda.Runtime.NODEJS_18_X,<br>  handler: &#39;dist/lambda.handler&#39;, <br>  code: lambda.Code.fromAsset(lambdaPath),<br>});</pre><p>So great, now we have a Lambda. If we were to invoke our Lambda using a test event in the AWS console we would get something like this</p><pre>{<br>  &quot;errorType&quot;: &quot;Error&quot;,<br>  &quot;errorMessage&quot;: &quot;Unable to determine event source based on event.&quot;,<br>  &quot;trace&quot;: [<br>    &quot;Error: Unable to determine event source based on event.&quot;,<br>    &quot;    at getEventSourceNameBasedOnEvent (/var/task/node_modules/@codegenie/serverless-express/src/event-sources/utils.js:130:9)&quot;,<br>    &quot;    at proxy (/var/task/node_modules/@codegenie/serverless-express/src/configure.js:38:51)&quot;,<br>    &quot;    at handler (/var/task/node_modules/@codegenie/serverless-express/src/configure.js:99:12)&quot;,<br>    &quot;    at Runtime.handler (/var/task/dist/lambda.js:27:12)&quot;<br>  ]<br>}</pre><p>This basically means that our lambda handler kicked in, tried to bootstrap NestJS, but was unable to process the incoming event.</p><p>Makes sense as we were sending</p><pre>{<br>  &quot;key1&quot;: &quot;value1&quot;,<br>  &quot;key2&quot;: &quot;value2&quot;,<br>  &quot;key3&quot;: &quot;value3&quot;<br>}</pre><h3>API Gateway</h3><p>So to make this work we need to invoke our Lambda via API Gateway. That way API Gateway can provide the correct event so that it can be processed by NestJS.</p><p>Compared to the event above it’s obvious that this contains a lot more info.</p><pre>{<br>    &quot;version&quot;: &quot;2.0&quot;,<br>    &quot;routeKey&quot;: &quot;$default&quot;,<br>    &quot;rawPath&quot;: &quot;/customers&quot;,<br>    &quot;rawQueryString&quot;: &quot;&quot;,<br>    &quot;headers&quot;: {<br>        &quot;accept&quot;: &quot;*/*&quot;,<br>        &quot;content-length&quot;: &quot;0&quot;,<br>        &quot;host&quot;: &quot;xxxxxxxx.execute-api.eu-central-1.amazonaws.com&quot;,<br>        &quot;user-agent&quot;: &quot;curl/8.1.2&quot;,<br>        &quot;x-amzn-trace-id&quot;: &quot;Root=1-65802b08-6849a21548edc16922c01b1e&quot;,<br>        &quot;x-forwarded-for&quot;: &quot;1.2.3.4&quot;,<br>        &quot;x-forwarded-port&quot;: &quot;443&quot;,<br>        &quot;x-forwarded-proto&quot;: &quot;https&quot;<br>    },<br>    &quot;requestContext&quot;: {<br>        &quot;accountId&quot;: &quot;949508759827&quot;,<br>        &quot;apiId&quot;: &quot;7pm1tlano5&quot;,<br>        &quot;domainName&quot;: &quot;xxxxxxxx.execute-api.eu-central-1.amazonaws.com&quot;,<br>        &quot;domainPrefix&quot;: &quot;xxxxxxxx&quot;,<br>        &quot;http&quot;: {<br>            &quot;method&quot;: &quot;GET&quot;,<br>            &quot;path&quot;: &quot;/customers&quot;,<br>            &quot;protocol&quot;: &quot;HTTP/1.1&quot;,<br>            &quot;sourceIp&quot;: &quot;84.198.159.234&quot;,<br>            &quot;userAgent&quot;: &quot;curl/8.1.2&quot;<br>        },<br>        &quot;requestId&quot;: &quot;QIupTgwMFiAEMKg=&quot;,<br>        &quot;routeKey&quot;: &quot;$default&quot;,<br>        &quot;stage&quot;: &quot;$default&quot;,<br>        &quot;time&quot;: &quot;18/Dec/2023:11:20:40 +0000&quot;,<br>        &quot;timeEpoch&quot;: 1702898440040<br>    },<br>    &quot;isBase64Encoded&quot;: false<br>}</pre><p>But how do we hook up our NestJS to API Gateway ?</p><p>Well there are several ways to go about it. And I’m going to be discussing 3 of them</p><ul><li>API Gateway (v2) HTTP API with a default route</li><li>API Gateway (v2) HTTP API with a prefixed route</li><li>API Gateway REST API</li></ul><h4>API Gateway (v2) HTTP API with a default route</h4><p>Let’s start with the most simple one, using an API Gateway HTTP API with a default integration</p><pre>const api = new apigatewayv2.HttpApi(this, &#39;HttpApi&#39;, {<br>  defaultIntegration: new HttpLambdaIntegration(<br>        &#39;LambdaIntegration&#39;, <br>        nestJsLambda)<br>});</pre><p>This will create our Api Gateway V2 (HTTP) API and an integration to our lambda. It uses the $default route, acting as a catch-all so that all of our requests will be routed to our Lambda.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cgSm-I50Pkl_479WuQ1GQw.png" /></figure><p>What this means is that all of the requests that will be coming into your API gateway will be forwared to the lambda.</p><p>So imagine your NestJS having lots of internal routes like</p><ul><li>GET /customers</li><li>GET /customers/123</li><li>DELETE /customers/123</li><li>GET /orders</li><li>POST /orders</li><li>….</li></ul><p>Then all of these will work becasue they will be handled by the $default catch-all route and your NestJS backend will process them.</p><p>If you want to learn more about how API gateway handles routes, make sure to checkout the following post</p><p><a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-routes.html">Working with routes for HTTP APIs</a></p><h4>API Gateway (v2) HTTP API with a prefixed route</h4><p>Now imagine you would like to expose your NestJS backend under a dedicated /api route, you could continue using the $default route and use the following snippet of code in your NestJS bootstrap.</p><pre>nestApp.setGlobalPrefix(&#39;api&#39;);</pre><p>You can also use the AWS CDK to generate a specific path in API gateway instead of the $default path</p><p>Notice how we need to use the greedy path variable {proxy+}</p><pre>// Define the API Gateway with a custom path<br>const api = new apigatewayv2.HttpApi(this, &#39;HttpApi&#39;);<br><br>api.addRoutes({<br>  path: &#39;/api/{proxy+}&#39;,<br>  methods: [apigatewayv2.HttpMethod.ANY],<br>  integration: new HttpLambdaIntegration(&#39;LambdaIntegration&#39;, nestJsLambda),<br>});</pre><p>This is how it looks like in the API GW console, allowing to make calls like /api/customers/ or /api/customers/123</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O0zeegfwBAPq5yY9P5vJ1g.png" /></figure><p>Without the greedy path variable {proxy+} we would only be able to call /api and calls like /api/cinstomers would not match.</p><p>But remember, in order for this /api prefix to work, you need to ensure that in your NestJS application you also have a global prefix using the setGlobalPrefix method.</p><h3>API Gateway REST API</h3><p>Another way to expose your NestJS is to not use an HTTP API but to use a REST API via Api Gateway.</p><p>REST APIs exposed via API Gateway do offer some additional features that HTTP APIs exposed via API Gateway don’t have. So if you’re looking at</p><ul><li>Web Application Firewall</li><li>Private APIs</li><li>API keys</li><li>Rate limiting</li><li>Caching</li></ul><p>you might want to look into REST APIs on API Gateway.</p><p>Again everything can be created using AWS CDK</p><pre>const restApi = new apigateway.RestApi(this, &#39;CustomerLambdaApi&#39;, {<br>  restApiName: &#39;NestJS REST API&#39;<br>});<br><br>const proxyResource = restApi.root.addResource(&#39;{proxy+}&#39;); // Catch-all for any subpath<br>proxyResource.addMethod(&#39;ANY&#39;,new apigateway.LambdaIntegration(nestJsLambda));</pre><p>And it will look like this in the AWS console</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zGcrLFyBwYLOySoybnl7ag.png" /></figure><p>A full comparison between REST APIs and HTTP APIs can be found here :</p><p><a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-vs-rest.html">Choose between REST APIs and HTTP APIs</a></p><h3>Errors</h3><p>Some errors you might come across include this one coming from NestJS itself.</p><p>This is when NestJS was unable to find a route for the incoming request.</p><p>For example imaging having an HTTP API with all of your /api/{proxy+} routes going to NestJS, but you haven’t defined a global /api prefix in NestJS</p><pre>{&quot;message&quot;:&quot;Cannot GET /api/customers&quot;,&quot;error&quot;:&quot;Not Found&quot;,&quot;statusCode&quot;:404}</pre><p>This is when the HTTP API Gateway cannot match a route. For example when there is no catch-all route, and your NestJS is routed via an /api route but you specify /customers</p><pre>{&quot;message&quot;:&quot;Not Found&quot;}</pre><p>This is when the REST API Gateway cannot match a route.</p><pre>{&quot;message&quot;:&quot;Missing Authentication Token&quot;}</pre><h3>Conclusion</h3><p>I like the idea of using NestJS as a serverless backend. It is a well thought out backend framework containing lots of constructs that empose a certain structure that I can appreciate.</p><p>Now there are some people that are opposing this fat lambda or lambda-lith approach, and even AWS mentioned it in their re:Invent 2023 talk about Best practices for serverless developers (SVS401). Be sure to check it out here.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FsdCA0Y7QDrM%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DsdCA0Y7QDrM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FsdCA0Y7QDrM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/baff40df8ae7fe541b7155cc5cec366f/href">https://medium.com/media/baff40df8ae7fe541b7155cc5cec366f/href</a></iframe><p>During the talk they did mention that both <strong>lambda-liths</strong> and <strong>micro-lambas</strong> are not ideal.</p><p>1 big Lambda-lith being too bloated and too many micro-lambdas causing operational overhead.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35B8neMwGLjtDBsOXpavWw.png" /></figure><p>They did mention <strong>pragmatic lambas</strong> offering the best of both worlds without really elaborating how to develop these pragmatic lambdas.</p><p>Perhaps these pragmatic lambdas could be mini NestJS backends, scoped around a certain bounded context.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GhLH5A1S46YOKhDoi2z1Aw.png" /></figure><p>Frameworks like SST and SAM are promoting these micro lambas (1 route = 1 function) but I haven’t seen any examples coming out of AWS on how exactly we should implement these pragmatic lambas.</p><p>If anyone has any thoughts on this feel free to let me know.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cbf5e61a6199" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Running your Sprint Boot App on EC2]]></title>
            <link>https://medium.com/spring-boot-tips/running-your-sprint-boot-app-on-ec2-9115a67e6883?source=rss-9ac28ff4a11b------2</link>
            <guid isPermaLink="false">https://medium.com/p/9115a67e6883</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[systemd]]></category>
            <dc:creator><![CDATA[Davy De Waele]]></dc:creator>
            <pubDate>Sun, 10 Dec 2023 14:18:10 GMT</pubDate>
            <atom:updated>2023-12-10T14:18:10.722Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post I wanted to quickly document how you can run your Spring Boot application on an EC2 instance.</p><h4>Why systemd</h4><p>There are many ways to run Spring Boot applications in the cloud.</p><p>A popular one is using a container orchestration offering like AWS Elastic Container Service, where you would wrap your Spring Boot application in a container and have it deployed via ECS.</p><p>Sometimes however you want something setup quick and dirty, without the overhead of setting up ECS , loadbalancers and targetgroups.</p><p>That’s where EC2 and systemd come into play.</p><p>The use-case here being the need to run a Spring Boot application on an EC2 instance without too much hassle.</p><p>I’m going to be using Amazon Linux 2023 as the base EC2 instance image.</p><pre>ssh ec2<br><br>   ,     #_<br>   ~\_  ####_        Amazon Linux 2023<br>  ~~  \_#####\<br>  ~~     \###|<br>  ~~       \#/ ___   https://aws.amazon.com/linux/amazon-linux-2023<br>   ~~       V~&#39; &#39;-&gt;<br>    ~~~         /<br>      ~~._.   _/<br>         _/ _/<br>       _/m/&#39;</pre><p><strong>systemd</strong> is available on the Amazon Linux 2023 as you can see by the output of the systemctl list-unit-files | grep enabledcommand.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6568916592b230d55f9b51a5a8ba1bd2/href">https://medium.com/media/6568916592b230d55f9b51a5a8ba1bd2/href</a></iframe><p><strong>systemd</strong> has the notion of services defined in service files that are located in the /etc/systemd/system folder</p><pre>-rw-r--r--. 1 root root   616 Sep 26 15:34 amazon-cloudwatch-agent.service<br>drwxr-xr-x. 2 root root     6 Oct 25 18:44 httpd.service.d<br>drwxr-xr-x. 2 root root    50 Nov 10 19:54 network-online.target.wants<br>lrwxrwxrwx. 1 root root    43 Nov 10 19:54 dbus.service -&gt; /usr/lib/systemd/system/dbus-broker.service<br>lrwxrwxrwx. 1 root root    48 Nov 10 19:54 dbus-org.freedesktop.resolve1.service -&gt; /usr/lib/systemd/system/systemd-resolved.service<br>lrwxrwxrwx. 1 root root    48 Nov 10 19:54 dbus-org.freedesktop.network1.service -&gt; /usr/lib/systemd/system/systemd-networkd.service<br>drwxr-xr-x. 2 root root    35 Nov 10 19:54 basic.target.wants<br>drwxr-xr-x. 2 root root    32 Nov 10 19:54 getty.target.wants<br>lrwxrwxrwx. 1 root root    37 Nov 10 19:54 ctrl-alt-del.target -&gt; /usr/lib/systemd/system/reboot.target<br>drwxr-xr-x. 2 root root    35 Nov 10 19:54 chronyd.service.wants<br>drwxr-xr-x. 2 root root   109 Nov 10 19:54 sockets.target.wants<br>drwxr-xr-x. 2 root root    31 Nov 10 19:54 remote-fs.target.wants<br>drwxr-xr-x. 2 root root    33 Nov 10 19:54 rpc-statd.service.requires<br>drwxr-xr-x. 2 root root    33 Nov 10 19:54 rpc-statd-notify.service.requires<br>drwxr-xr-x. 2 root root    33 Nov 10 19:54 rpc-gssd.service.requires<br>drwxr-xr-x. 2 root root    33 Nov 10 19:54 nfs-server.service.requires<br>drwxr-xr-x. 2 root root    33 Nov 10 19:54 nfs-mountd.service.requires<br>drwxr-xr-x. 2 root root    33 Nov 10 19:54 nfs-idmapd.service.requires<br>drwxr-xr-x. 2 root root    33 Nov 10 19:54 nfs-blkmap.service.requires<br>drwxr-xr-x. 2 root root    64 Nov 10 19:54 sysstat.service.wants<br>drwxr-xr-x. 2 root root   212 Nov 10 19:55 sysinit.target.wants<br>drwxr-xr-x. 2 root root   119 Nov 10 19:55 cloud-init.target.wants<br>drwxr-xr-x. 2 root root    44 Nov 10 19:55 systemd-homed.service.wants<br>lrwxrwxrwx. 1 root root    45 Nov 10 19:55 dbus-org.freedesktop.home1.service -&gt; /usr/lib/systemd/system/systemd-homed.service<br>drwxr-xr-x. 2 root root    74 Nov 10 19:55 timers.target.wants<br>drwxr-xr-x. 2 root root 16384 Dec  8 15:47 multi-user.target.wants</pre><h4>Defining our Spring Boot service</h4><p>So lets start our favorite editor and issue the following command to create a new systemd service defintion for our spring-boot-docker-memory-demo application</p><pre>sudo vi /etc/systemd/system/spring-boot-docker-memory-demo.service</pre><p>We’ll provide the following service configuration. Notice how we use the Restart properties to ensure that our service will always be up and running, even after it has been killed</p><pre>[Unit]<br>Description=spring-boot-docker-memory-demo<br>After=syslog.target<br><br>[Service]<br>User=ec2-user<br>ExecStart=/spring-boot-docker-memory-demo-0.0.1-SNAPSHOT.jar<br>SuccessExitStatus=143<br>Restart=always<br>RestartSec=5<br><br>[Install]<br>WantedBy=multi-user.target</pre><p>There are <a href="https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html">lots of systemd options</a> to explore but we’re going to be leaving it at that.</p><p>To enable our systemd service just issue this command</p><pre>sudo systemctl enable spring-boot-docker-memory-demo.service<br>Created symlink /etc/systemd/system/multi-user.target.wants/spring-boot-docker-memory-demo.service → /etc/systemd/system/spring-boot-docker-memory-demo.service.</pre><p>Now at this point our systemd service is active but hasn’t started yet.</p><pre>[ec2-user@ip-172-31-0-241 /]$ sudo systemctl status spring-boot-docker-memory-demo.service<br>○ spring-boot-docker-memory-demo.service - spring-boot-docker-memory-demo<br>     Loaded: loaded (/etc/systemd/system/spring-boot-docker-memory-demo.service; enabled; preset: disabled)<br>     Active: inactive (dead)</pre><p>For the service to start we need to issue the sudo systemctl start spring-boot-docker-memory-demo.service command</p><pre>[ec2-user@ip-172-31-0-241 /]$ sudo systemctl status spring-boot-docker-memory-demo.service <br>● spring-boot-docker-memory-demo.service - spring-boot-docker-memory-demo<br>     Loaded: loaded (/etc/systemd/system/spring-boot-docker-memory-demo.service; enabled; preset: disabled)<br>     Active: active (running) since Sat 2023-12-09 16:52:29 UTC; 18s ago<br>   Main PID: 5913 (spring-boot-doc)<br>      Tasks: 29 (limit: 1114)<br>     Memory: 109.0M<br>        CPU: 6.160s<br>     CGroup: /system.slice/spring-boot-docker-memory-demo.service<br>             ├─5913 /bin/bash /spring-boot-docker-memory-demo-0.0.1-SNAPSHOT.jar<br>             └─5928 /usr/bin/java -Dsun.misc.URLClassPath.disableJarChecking=true -jar //spring-boot-docker-memory-demo-0.0.1-SNAPSHOT.jar<br><br>Dec 09 16:52:32 ip-172-31-0-241.eu-central-1.compute.internal spring-boot-docker-memory-demo-0.0.1-SNAPSHOT.jar[5928]:  :: Spring Boot ::                (v3.1.4)<br>Dec 09 16:52:32 ip-172-31-0-241.eu-central-1.compute.internal spring-boot-docker-memory-demo-0.0.1-SNAPSHOT.jar[5928]: 2023-12-09T16:52:32.171Z  INFO 5928 --- [           main] .s.SpringBootDockerMemoryDemoApplication : Starting SpringBootDockerMemoryDemoApplication v0.0.&gt;<br>Dec 09 16:52:32 ip-172-31-0-241.eu-central-1.compute.internal spring-boot-docker-memory-demo-0.0.1-SNAPSHOT.jar[5928]: 2023-12-09T16:52:32.174Z  INFO 5928 --- [           main] .s.SpringBootDockerMemoryDemoApplication : No active profile set, falling back to 1 default pro&gt;<br>Dec 09 16:52:34 ip-172-31-0-241.eu-central-1.compute.internal spring-boot-docker-memory-demo-0.0.1-SNAPSHOT.jar[5928]: 2023-12-09T16:52:34.537Z  INFO 5928 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)<br>Dec 09 16:52:34 ip-172-31-0-241.eu-central-1.compute.internal spring-boot-docker-memory-demo-0.0.1-SNAPSHOT.jar[5928]: 2023-12-09T16:52:34.560Z  INFO 5928 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]<br>Dec 09 16:52:34 ip-172-31-0-241.eu-central-1.compute.internal spring-boot-docker-memory-demo-0.0.1-SNAPSHOT.jar[5928]: 2023-12-09T16:52:34.561Z  INFO 5928 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.13]<br>Dec 09 16:52:34 ip-172-31-0-241.eu-central-1.compute.internal spring-boot-docker-memory-demo-0.0.1-SNAPSHOT.jar[5928]: 2023-12-09T16:52:34.959Z  INFO 5928 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext<br>Dec 09 16:52:34 ip-172-31-0-241.eu-central-1.compute.internal spring-boot-docker-memory-demo-0.0.1-SNAPSHOT.jar[5928]: 2023-12-09T16:52:34.961Z  INFO 5928 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed&gt;<br>Dec 09 16:52:36 ip-172-31-0-241.eu-central-1.compute.internal spring-boot-docker-memory-demo-0.0.1-SNAPSHOT.jar[5928]: 2023-12-09T16:52:36.241Z  INFO 5928 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context &gt;<br>Dec 09 16:52:36 ip-172-31-0-241.eu-central-1.compute.internal spring-boot-docker-memory-demo-0.0.1-SNAPSHOT.jar[5928]: 2023-12-09T16:52:36.287Z  INFO 5928 --- [           main] .s.SpringBootDockerMemoryDemoApplication : Started SpringBootDockerMemoryDemoApplication in 5.1&gt;<br>[ec2-user@ip-172-31-0-241 /]$</pre><h4>Inspecting log files</h4><p>When the service is started you can inspect the logs using we can check the logs by issuing the journalctl -u spring-boot-docker-memory-democommand</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/61a46a1f1a922d18685ac5d00a9ea7ee/href">https://medium.com/media/61a46a1f1a922d18685ac5d00a9ea7ee/href</a></iframe><p>Once the service is started, you will see that your service will always be up and running, even</p><ul><li>After restarting your ec2 instances</li><li>Killing your java process using the kill command</li></ul><h4>References</h4><ul><li><a href="https://docs.spring.io/spring-boot/docs/1.4.0.RC1/reference/html/deployment-install.html">https://docs.spring.io/spring-boot/docs/1.4.0.RC1/reference/html/deployment-install.html</a></li><li><a href="https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html">https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9115a67e6883" width="1" height="1" alt=""><hr><p><a href="https://medium.com/spring-boot-tips/running-your-sprint-boot-app-on-ec2-9115a67e6883">Running your Sprint Boot App on EC2</a> was originally published in <a href="https://medium.com/spring-boot-tips">Spring Boot Tips</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Instant Spring Boot Gratification]]></title>
            <link>https://medium.com/spring-boot-tips/instant-spring-boot-gratification-5c24884ad32b?source=rss-9ac28ff4a11b------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c24884ad32b</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[spring-initializr]]></category>
            <dc:creator><![CDATA[Davy De Waele]]></dc:creator>
            <pubDate>Fri, 01 Sep 2023 19:05:36 GMT</pubDate>
            <atom:updated>2023-09-01T19:07:20.200Z</atom:updated>
            <content:encoded><![CDATA[<p>As a software developer working on large projects you are often faced with issues or bugs that you really want to isolate and get down to the core without loosing yourself in the rest of the project.</p><p>In large code-bases it’s not always clear what the root cause for a particular issue is. It can be the result from other code, configuration anywhere in the project.</p><p>If you’re using third party frameworks like Spring Boot, I sometimes find the need to <strong>isolate</strong> a certain piece of functionality or code that I can incorporate in a very <strong>small dedicated Spring Boot sample project</strong>, just to make sure you can really zoom in on the issue.</p><p>This also helps later when logging issues in Github so you can provide a sample project.</p><p>In order to do that you need something to create a boilerplate Spring Boot project quickly.</p><blockquote><strong>An excellent time to start harnessing Spring Boot Initializr’s capabilities.</strong></blockquote><p>Now, you may now <strong>Spring Boot Initializr </strong>from the <a href="http://start.spring.io/">start.spring.io</a> webpage</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JESE1abz1y-TABeDhir2ZQ.png" /><figcaption>start.spring.io webpage</figcaption></figure><p>Here you can fill in some properties that will allow you to download a zip file with your project.</p><p>From the page you can</p><ul><li>Choose what version of Spring Boot you want</li><li>Choose between Maven or Gradle</li><li>Choose the dependencies that you want to include in your project</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*eLcjonVL89zdRzfYWTwKxw.png" /></figure><p>And you’ll end up with a nice zip-file containing your project that you can include in your favourite IDE.</p><p>You can even explore the content of your Spring Boot project straight from within the web interface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aYAD1xJiAHNA8Xy_607NPA.png" /></figure><blockquote>And for the scripting virtuosos among us, we can use good old curl from our favorite terminal to generate the spring boot archive and extract it on the fly.</blockquote><pre>curl -s https://start.spring.io/starter.tgz -d dependencies=web -d groupId=com.example -d artifactId=demo -d name=demo -d language=java -d type=maven-project -d baseDir=demo | tar -xpvf -<br>x demo/<br>x demo/HELP.md<br>x demo/.mvn/<br>x demo/.mvn/wrapper/<br>x demo/.mvn/wrapper/maven-wrapper.jar<br>x demo/.mvn/wrapper/maven-wrapper.properties<br>x demo/mvnw.cmd<br>x demo/src/<br>x demo/src/test/<br>x demo/src/test/java/<br>x demo/src/test/java/com/<br>x demo/src/test/java/com/example/<br>x demo/src/test/java/com/example/demo/<br>x demo/src/test/java/com/example/demo/DemoApplicationTests.java<br>x demo/src/main/<br>x demo/src/main/java/<br>x demo/src/main/java/com/<br>x demo/src/main/java/com/example/<br>x demo/src/main/java/com/example/demo/<br>x demo/src/main/java/com/example/demo/DemoApplication.java<br>x demo/src/main/resources/<br>x demo/src/main/resources/application.properties<br>x demo/src/main/resources/templates/<br>x demo/src/main/resources/static/<br>x demo/.gitignore<br>x demo/pom.xml<br>x demo/mvnw</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c24884ad32b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/spring-boot-tips/instant-spring-boot-gratification-5c24884ad32b">Instant Spring Boot Gratification</a> was originally published in <a href="https://medium.com/spring-boot-tips">Spring Boot Tips</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>