programming language, superset of JavaScript that compiles to JavaScript

TypeScript (TS) is a high-level programming language that adds static typing with optional type annotations to JavaScript. It is designed for developing large applications. It transpiles to JavaScript. It is developed by … Wikipedia
Factsheet
Family ECMAScript
Designed by Microsoft,
Anders Hejlsberg,
Luke Hoban
Factsheet
Family ECMAScript
Designed by Microsoft,
Anders Hejlsberg,
Luke Hoban
🌐
TypeScript
typescriptlang.org › download
TypeScript: How to set up TypeScript
Then you use a dependency manager like npm, yarn or pnpm to download TypeScript into your project. ... All of these dependency managers support lockfiles, ensuring that everyone on your team is using the same version of the language. You can then run the TypeScript compiler using one of the ...
🌐
Yarn
classic.yarnpkg.com › en › package › typescript
Yarn
For Yarn 2+ docs and migration guide, see yarnpkg.com.
Top answer
1 of 2
1

As my comment mentions in the original question, from the yarn documentation:

TypeScript uses its own resolver as well. In this case the situation is a bit more complex - the TS team has some concerns about allowing third-party hooks inside the tsc compiler, meaning that we can’t work with it at the moment. That being said, TypeScript isn’t only tsc and as such we’ve been able to add PnP support to the popular ts-loader - meaning that as long as you compile your TypeScript through Webpack, everything works well! Consult the dedicated section about it for more information.

To enable yarn package resolution when using Typescript you have to use webpack with ts-loader. This is how I resolved it.

  • install the neccessary dependencies:

npm install webpack webpack-cli pnp-webpack-plugin ts-loader

  • Create a 'webpack.config.js' file in your project root directory with the following content:
const path = require('path');
const PnpWebpackPlugin = require('pnp-webpack-plugin');
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');

const commonConfig = {
  mode: 'development',
  devtool: 'source-map',
  plugins: [
    new NodePolyfillPlugin(),
  ],
  output: {
    filename: '[name].js',
    path: path.resolve(__dirname, 'dist'),
  },
  node: {
    __dirname: false,
  },
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: 'ts-loader',
        exclude: /node_modules/,
      },
    ],
  },
  resolve: {
    extensions: ['.tsx', '.ts', '.js'],
    plugins: [PnpWebpackPlugin],
  },
  resolveLoader: {
    plugins: [PnpWebpackPlugin.moduleLoader(module)],
  },
};

module.exports = [
  Object.assign(
    {
      target: 'electron-main',
      entry: { main: './src/main.ts' },
    },
    commonConfig
  ),
  Object.assign(
    {
      target: 'electron-renderer',
      entry: { preload: './src/preload.ts' },
    },
    commonConfig
  ),
];
  • I updated my package.json with scripts to run webpack:
{
  "name": "ElectroMega",
  "packageManager": "[email protected]",
  "private": true,
  "scripts": {
    "build": "webpack",
    "prestart": "yarn run build",
    "start": "electron ./dist/main.js"
  },
  "devDependencies": {
    "html-webpack-plugin": "^5.3.2",
    "node-polyfill-webpack-plugin": "^1.1.4",
    "pnp-webpack-plugin": "^1.7.0",
    "ts-loader": "^9.2.6",
    "typescript": "^4.4.3",
    "webpack": "^5.54.0",
    "webpack-cli": "^4.8.0"
  },
  "dependencies": {
    "@tsconfig/node14": "^1.0.1",
    "@types/node": "^16.9.6",
    "electron": "^14.0.1"
  }
}
  • Then you should be able to build your code with the command:

yarn build

My solution was a result of following the webpack GettingStarted section that explained much of the troubles I had, and the basics of using webpack.

2 of 2
0

FWIW, iamkneel's answer from above worked for my. Had an express app that I was using Typescript for and set it up with yarn. Setting nodeLinker: node-modules in the .yarnrc.yml file took care of the compile issue.

🌐
Medium
medium.com › @tharindugimras › typescript-setup-with-nodejs-yarn-package-manager-nodemon-fa9fb2275655
Typescript setup with Nodejs + Yarn Package manager + Nodemon | by Tharindu Gimras | Medium
March 3, 2023 - In this project, you can see that I’m using yarn as my package manager. To initialize the configuration file for the yarn package manager, let’s run these commands in your terminal/command line at typescript_with_node/ path.
🌐
WebDevAssist
webdevassist.com › typescript › typescript-installation
How to install TypeScript
This is the easiest way to install typescript. If you have installed any package manager like npm, yarn or pnpm, you can install typescript with just one line:
🌐
Plain English
plainenglish.io › blog › getting-started-with-yarn-3-and-typescript-125e7b537e6c
Getting Started with Yarn 3 and TypeScript
To get started you'll want to import the TypeScript plugin for Yarn, and install TypeScript itself of course, along with getting the environment setup using @yarnpkg/sdks we learned about earlier.
🌐
Yarn
yarnpkg.com › package
typescript | Yarn - Package Manager
Yarn guarantees that installs that work today will keep working the same way in the future.
🌐
GitHub
gist.github.com › jbsulli › 881cb2e5d5d9c4e5e5d8736755c11ffb
Typescript Yarn 3 Plug'n'Play zero-install monorepo for VSCode · GitHub
Note: it's important that you have typescript installed at the root so that this step installs typescript sdk to .yarn/sdks/typescript. This is what VSCode will use to handle the Plug'n'Play (PnP) modules. Otherwise, you'll get a lot of Cannot find type definition file for ...
Find elsewhere
🌐
Medium
medium.com › swlh › getting-started-with-yarn-2-and-typescript-43321a3acdee
Getting started with Yarn 2 and TypeScript | by Sinclair | The Startup | Medium
October 26, 2021 - ➤ YN0000: └ Completed in 0.22s ➤ YN0000: ┌ Link step ➤ YN0000: └ Completed ➤ YN0000: Done in 0.54s PS C:\…> yarn plugin import typescript ➤ YN0000: Downloading https://.../plugin-typescript.js ➤ YN0000: Saving the new plugin in .yarn/plugins/@yarnpkg/plugin-typescript.cjs ➤ YN0000: Done in 0.67sDid I mention Yarn Modern is fast? This just installs typescript, of course, but also adds the TypeScript plugin!
🌐
GitHub
github.com › yarnpkg › yarn › issues › 2154
yarn installs incorrect version for typescript, because dist-tag is ignored · Issue #2154 · yarnpkg/yarn
September 4, 2016 - Install [email protected] again. Please mention your node.js, yarn and operating system version.
Published   Dec 05, 2016
🌐
Yarn
yarnpkg.com › overview
@yarnpkg/plugin-typescript | API | Yarn
❯ yarn/packages/plugin-typescript ❯ yarn add lodash ➤ YN0000: ·
🌐
Create React App
create-react-app.dev › docs › adding-typescript
Adding TypeScript | Create React App
If you've previously installed create-react-app globally via npm install -g create-react-app, we recommend you uninstall the package using npm uninstall -g create-react-app or yarn global remove create-react-app to ensure that npx always uses ...
🌐
Medium
losikov.medium.com › part-1-project-initial-setup-typescript-node-js-31ba3aa7fbf1
Part 1. Project initial setup: TypeScript + Node.js | by Alex Losikov | Medium
November 3, 2020 - Install initial dependencies (-D flag is a development dependency): $ yarn add @types/node typescript $ yarn add -D ts-node
🌐
npm
npmjs.com › package › @yarnpkg › plugin-typescript
@yarnpkg/plugin-typescript - npm
Latest version: 4.1.3, last published: a month ago. Start using @yarnpkg/plugin-typescript in your project by running `npm i @yarnpkg/plugin-typescript`. There are 2 other projects in the npm registry using @yarnpkg/plugin-typescript.
      » npm install @yarnpkg/plugin-typescript
    
Published   Jun 03, 2025
Version   4.1.3
🌐
GitHub
github.com › yarnpkg › yarn › issues › 4226
Installing Typescript definitions for react and react-addons-test-utils is inconsistent with npm · Issue #4226 · yarnpkg/yarn
August 22, 2017 - If the current behavior is a bug, please provide the steps to reproduce. yarn add @types/react@^15.6.1 @types/react-addons-test-utils --save-dev · Creates the following.. node_modules/@types/react (containing react 15.6 Typescript definitions) node_modules/@types/react-addons-test-utils node_modules/@types/react-addons-test-utils/node_modules/@types/react (containing react 16.0 Typescript definitions)
Published   Aug 22, 2017
🌐
Yarn
yarnpkg.com › editor sdks
Editor SDKs | Yarn
(let ((project-directory (car (dir-locals-find-file default-directory)))) (setq lsp-clients-typescript-server-args `("--tsserver-path" ,(concat project-directory ".yarn/sdks/typescript/bin/tsserver") "--stdio"))))))) ... TypeScript support should then work out of the box with nvim-lspconfig and theia-ide/typescript-language-server. Install the ZipFS extension, which is maintained by the Yarn team.
🌐
Semaphore
semaphore.io › home › typescript monorepos with yarn
TypeScript Monorepos with Yarn - Semaphore
September 8, 2021 - Fortunately, with a bit of tweaking, we can extend it to TypeScript. Fork and clone the following GitHub repository, which has a couple of packages to experiment with. ... Let’s get going. To configure workspaces, switch to the latest Yarn version: ... Yarn installs on .yarn/releases and can be safely checked in the repo.
🌐
Jest
jestjs.io › getting started
Getting Started · Jest
First, make sure you followed the instructions on using Babel above. Next, install the @babel/preset-typescript: npm · Yarn · pnpm · npm install --save-dev @babel/preset-typescript · yarn add --dev @babel/preset-typescript ·