I have @types/node installed. I'm using Yarn 2 (PnP). Seems like Typescript can't find the @types/node package?
Running yarn build with the build script being webpack shows errors about cannot resolving modules (path, buffer etc)
Running tsc shows TS2688: Cannot find type definition file for 'node'.
Running 'ts-node' however does work properly.
My tsconfig.json is below:
{
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"module": "commonjs",
"target": "es6",
"jsx": "react",
"allowJs": true,
"moduleResolution": "node",
"esModuleInterop": true,
"lib": [
"ES2020",
"DOM"
],
"types": ["node"]
},
"include": [
"src/**/*"
]
}
My webpack.config.js
module.exports = {
mode: "development",
devtool: "inline-source-map",
entry: "./src/server.ts",
output: {
filename: "bundle.js"
},
resolve: {
extensions: [".tsx", ".ts", ".js"]
},
module: {
rules: [
{
test: /\.tsx?$/,
use: [{
loader: 'ts-loader',
options: {
transpileOnly: true,
experimentalWatchApi: true,
onlyCompileBundledFiles: true,
},
}],
exclude: /node_modules/,
}
]
}
};