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
Electron + Angular 2/4 addition:
On top of adding the 'node' type to ts.config various files, what eventually worked for me was adding the next to the
typings.d.ts
file:
declare var window: Window;
interface Window {
process: any;
require: any;
}
Note that my case is developing with Electron + Angular 2/4. I needed the require on the window global.
Just in addition to cgatian's answer, for TypeScript 1.x
If you are still seeing errors, please specifically provide index.d.ts in your compiler options.
"files": [
"typings/index.d.ts"
]
If you can compile code, but Visual Studio 2015 marks 'require' functions as errors with error text cannot find name 'require' or cannot resolve symbol 'require', update TypeScript for Visual Studio 2015 to the latest version (at the moment 2.1.5) and update ReSharper (if you use it) to at least version 2016.3.2.
I had this annoying problem for a while and couldn't find a solution, but I finally resolved it this way.
import * as mongoose from 'mongoose'
If you are facing this issue in a .ts file which is only there to provide you some constant values, then you can just
rename your .ts file to .js file
and the error will not come again.
For me it is resolved by adding types to the angular compiler options.
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"types": [ "node" ]
}