when I add the following line at the beginning of app.ts
const crypto = require('crypto');
I get the following error,
Cannot redeclare block-scoped variable 'crypto'
Seems like it has been globally imported from somewhere else, this is how my tsconfig.json looks like
{
"compilerOptions": {
"allowJs": true,
"outDir": "./dist",
"target": "ES6",
"module": "commonjs",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": true,
"noImplicitAny": false,
"strictNullChecks": true,
"noUnusedLocals": true,
"types": [
"node"
],
"typeRoots": [
"./node_modules/@types"
],
"lib": ["es2015", "dom"]
},
"include": [
"./src/"
]
}
PS: The above error is when I try to transpile it from terminal. I am using VisualStdioCode, in VisualStdioCode it doesn't show any error as it points to,
/path/to/VisualStdioCode/Visual Studio Code.app/Contents/Resources/app/extensions/typescript/node_modules/typescript/lib/lib.dom.d.ts
EDIT(solved): The problem here was slightly different than cannot redeclare block scoped variable (typescript) The aim of this question was to detect duplicate import source than use ES6 non explicit assignment to atomatically solve it for us. The solution here was to import either from libs or node_modules and not to scope it unlike mentioned in answers there.