For either case:
document.getElementById('body'); // or window.document.getElementById('body');
I get error TS2304: Cannot find name 'window'.
Am I missing something in tsconfig.json
for a definition file I should install?
I get the message when running tsc
and in vscode
tsconfig.json:
{ "compilerOptions": { "allowJs": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "jsx": "react", "module": "commonjs", "moduleResolution": "node", "noEmitOnError": true, "noImplicitAny": false, "sourceMap": true, "suppressImplicitAnyIndexErrors": true, "target": "ES2016", "typeRoots": [ "node_modules/@types/", "typings/index.d.ts" ] }, "exclude": [ "node_modules", "**/*-aot.ts" ] }
My Answer: For use with tsconfig.json
I target es5
and use lib: ["es2015", "dom"]
To solve the error "Cannot find name module", install the node types by running npm i -D @types/node . If the error is not resolved, try adding node to your types array in tsconfig. json and restarting your IDE.
use
"lib": ["dom"]
in tsconfig.json
e.g.
{ "compilerOptions": { "lib": ["es5", "es6", "dom"], "outDir": "./dist/", "sourceMap": true, "noImplicitAny": true, "module": "commonjs", "target": "es6", "moduleResolution": "node", "jsx": "react" }, "include": ["./src/**/*"] }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With