My folder structure is as follows:
Code in XX.ts file:
var __dirname: string; console.log("__dirname: " + __dirname); // the output is undefined.
I tried: commented on the code var __dirname: string;, value __dirname: ...../apppaste into the current folder, for example ...../app/tsFolder.
var __dirname: string;
__dirname
...../app
...../app/tsFolder
Can anyone explain this?
Just run
npm install --save-dev @types/node
And if that doesn't work on its own, add
"types": ["node"]
in the field tsconfig.json compilerOptions.
tsconfig.json
compilerOptions
I assume that you are referencing the global variable nodejs __dirname .
.... /app, , XX.ts .... /app. js - __dirname (js ).
, , __dirname. nodejs , , :
declare var __dirname;
I tried npm i @ types / node without changes in tsconfig. You must ensure that the working directory path must be less than the maximum Windows limit.