TypeScript getting error TS2304: cannot find name ' require'

后端 未结 23 3188
Happy的楠姐
Happy的楠姐 2020-11-22 06:00

I am trying to get my first TypeScript and DefinitelyTyped Node.js application up and running, and running into some errors.

I am getting the error \"TS2304: Cannot

23条回答
  •  感动是毒
    2020-11-22 06:33

    1. Did you specify what module to use to transpile the code?
      tsc --target es5 --module commonjs script.ts
      You must do that to let the transpiler know that you're compiling NodeJS code. Docs.

    2. You must install mongoose definitions as well
      tsd install mongoose --save

    3. Do not use var to declare variables (unless necessary, which is a very rare case), use let instead. Learn more about that

提交回复
热议问题