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 - So it's faster than the npm package manager by reducing installation times by using the features mentioned above. Let’s create a folder named typescript_with_node. In that folder, you can start your project. First of all, let’s create an src folder in the project to contain our project source files. Let’s create your server.ts file which is the initialization of your server by using NodeJs. So your project structure now will be like this. ... In this project, you can see that I’m using yarn as my package manager.
🌐
Plain English
plainenglish.io › blog › getting-started-with-yarn-3-and-typescript-125e7b537e6c
Getting Started with Yarn 3 and TypeScript
Following the pattern, integration is as easy as possible thanks to plugins. 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
Yarn
Yarn guarantees that installs that work today will keep working the same way in the future.
🌐
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:
🌐
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
Find elsewhere
🌐
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
🌐
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 - Installing Typescript definitions for react and react-addons-test-utils is inconsistent with npm#4226 ... What is the current behavior? Performing a yarn add of @types/react@^15.6.1 and @types/react-addons-test-utils creates output that is inconsistent with npm install of the same packages.
Published   Aug 22, 2017
🌐
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 ...
🌐
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 ...
🌐
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 - PS C:\…> npm -g install yarn PS C:\…> mkdir <your-project> PS C:\…> cd <your-project> PS C:\…> yarn init ... Package information ...PS C:\…\your-project> yarn set version berry Resolving berry to a url…
🌐
GitHub
github.com › yarnpkg › yarn › issues › 2154
yarn installs incorrect version for typescript, because dist-tag is ignored · Issue #2154 · yarnpkg/yarn
September 3, 2016 - # yarn lockfile v1 typescript@^2.0.10: version "2.0.10" resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.0.10.tgz#ccdd4ed86fd5550a407101a0814012e1b3fac3dd" Now remove the yarn.lock and run $ yarn install.
Published   Dec 05, 2016
🌐
Yarn
yarnpkg.com › overview
@yarnpkg/plugin-typescript | API | Yarn
❯ yarn/packages/plugin-typescript ❯ yarn add lodash ➤ YN0000: · Yarn X.Y.Z ➤ YN0000: ┌ Resolution step ➤ YN0000: └ Completed in 0.24s ➤ YN0000: ┌ Fetch step ➤ YN0013: │ @types/lodash@npm:4.14.121 can't be found in the cache and will be fetched from the remote registry ...
🌐
Jest
jestjs.io › getting started
Getting Started · Jest
Jest supports TypeScript, via Babel. First, make sure you followed the instructions on using Babel above. Next, install the @babel/preset-typescript:
🌐
iO Flood
ioflood.com › blog › npm-typescript
NPM TypeScript Package | Quick Setup Guide
May 2, 2024 - For TypeScript projects, Yarn offers seamless integration much like npm. Here’s how you would initiate a new TypeScript project with Yarn: