Typescript compiler can t find node with yarn - Cannot find type definition file for node

0 votes

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/,
      }
    ]
  }
};
Jun 16, 2022 in TypeSript by Logan
• 2,140 points
5,605 views

1 answer to this question.

0 votes
I solved it on my computer by re-installing node.js, as the program yarn is relying on. Simply download node.js and run the installer - it was nothing to do with yarn packages, though I tried all sorts of yarn commands, even clearing the cache, as a puzzle as the project had previously compiled and run.
answered Jun 22, 2022 by Nina
• 3,060 points

Related Questions In TypeSript

0 votes
1 answer

Interface type check with Typescript

You can achieve what you want without ...READ MORE

answered May 31, 2022 in TypeSript by Nina
• 3,060 points
5,792 views
0 votes
1 answer
0 votes
1 answer

TypeScript and React Native: Are the type definitions for RN styles wrong?

You can test some of ways for ...READ MORE

answered Jun 10, 2022 in TypeSript by Nina
• 3,060 points
3,600 views
0 votes
1 answer
0 votes
1 answer

How to set meta tags using Angular universal SSR and ngx-seo plug-in?

first Install the plug-in with npm i ngx-seo ...READ MORE

answered Feb 11, 2022 in Others by narikkadan
• 63,680 points
2,175 views
0 votes
1 answer

Can't bind to 'ngModel' since it isn't a known property of 'input'

Just add this in the app.module.ts file: import { FormsModule ...READ MORE

answered Apr 30, 2022 in Other DevOps Questions by narikkadan
• 63,680 points
4,402 views
0 votes
1 answer

VS Code enforces semicolons, but why doesn't Angular and TypeScript not use it consistently?

JavaScript has a syntactic feature known as semicolon ...READ MORE

answered May 31, 2022 in TypeSript by Nina
• 3,060 points
4,788 views
0 votes
1 answer

Typescript: Can't find names - Error: cannot find name

A known issue: https://github.com/angular/angular/issues/4902 Core reason: the .d.ts file implicitly included ...READ MORE

answered Jun 7, 2022 in TypeSript by Nina
• 3,060 points
11,437 views
0 votes
1 answer

TypeScript error TS2304: cannot find name ' require'

Here's a really easy work around: declare var ...READ MORE

answered May 31, 2022 in TypeSript by Nina
• 3,060 points
13,821 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP