I'm having some trouble compiling typescript code with references to yarn installed packages. Tsc cant find the packages because yarn uses the Plug And Play system.
The tsc error:
src/main.ts:1:36 - error TS2307: Cannot find module 'electron'.
1 import { app, BrowserWindow } from 'electron';
~~~~~~~~~~
src/main.ts:2:18 - error TS2307: Cannot find module 'node:path'.
2 import path from 'node:path';
~~~~~~~~~~~
src/main.ts:8:42 - error TS2304: Cannot find name '__dirname'.
8 webPreferences: { preload: path.join(__dirname, 'preload.js') },
~~~~~~~~~
src/main.ts:23:7 - error TS2580: Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i @types/node`.
23 if (process.platform !== 'darwin') app.quit();
~~~~~~~
src/preload.ts:1:21 - error TS2307: Cannot find module 'node:process'.
1 import process from 'node:process';
~~~~~~~~~~~~~~
Found 5 errors.
I'm totaly new to yarn and wanted to test it out.
Am I missing something in my configurations? Searched all over but couldn't find any documentation about using Typescript with yarn installed dependencies. Or do even the typescript compiler work with yarn? Maybe a command I left out to generate the node_modules? The whole point of using yarn was to get away from that.
tsconfig:
{
"compilerOptions": {
"lib": ["es2020", "DOM"],
"module": "es2020",
"moduleResolution": "Node",
"target": "es2020",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"sourceMap": false,
"removeComments": true,
"preserveConstEnums": true,
"outDir": "dist",
"baseUrl": ".",
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
"include": ["src/**/*"]
}
package.json:
{
"name": "ElectroMega",
"packageManager": "yarn@3.0.2",
"private": true,
"devDependencies": {
"typescript": "^4.4.3"
},
"dependencies": {
"@tsconfig/node14": "^1.0.1",
"@types/node": "^16.9.6",
"electron": "^14.0.1"
}
}
I have my sourcefiles in a src folder in the root.