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 in TypeSript by Logan
• 2,140 points
64 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 by Nina
• 3,020 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 in TypeSript by Nina
• 3,020 points
232 views
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 in TypeSript by Nina
• 3,020 points
120 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 in Others by narikkadan
• 11,280 points
709 views
0 votes
0 answers

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

I have this  input in my component ...READ MORE

Apr 29 in Other DevOps Questions by Kichu
• 19,040 points
144 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 in TypeSript by Nina
• 3,020 points
48 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 in TypeSript by Nina
• 3,020 points
441 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 in TypeSript by Nina
• 3,020 points
1,412 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP