DEV Community

alɔeksandyr ippatev
alɔeksandyr ippatev

Posted on

 

How to fix problems with esbuild in Yarn

This plugin lets you use Yarn with esbuild. We use it in order to build Yarn itself!

  1. Add the plugin to your dependencies:
yarn add @yarnpkg/esbuild-plugin-pnp
Enter fullscreen mode Exit fullscreen mode
  1. Reference it via your esbuild configuration build API only:
import {pnpPlugin} from '@yarnpkg/esbuild-plugin-pnp';

await build({
  plugins: [pnpPlugin()],
  // ...
});
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
alexandervantrijffel profile image
Alexander van Trijffel

Can you share your full esbuild.config.js please? I am trying to get this working with Yarn 2. But with Yarn 2 PNP, I cannot run node esbuild.config.js in my project because packages resolving does not work when they are not present in node_modules. When I run node esbuild.config.mjs I get error Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'esbuild' imported from SNIP/esbuild.config.mjs

Collapse
 
alexandervantrijffel profile image
Alexander van Trijffel

Never mind, I found the solution. The build must be started with yarn node esbuild.config.js so that dependencies are resolved using .pnp.cjs if yarn is configured to use PnP.

11 Tips That Make You a Better Typescript Programmer

typescript

1 Think in {Set}

Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

#2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

#3 Use discriminated union instead of optional fields

...

Read the whole post now!