5- Configuring the TypeScript Compiler

From some reason, I couldn’t configure ts compiler with tsc --init command and tsconfig.json file doesn’t show up.
If some one could help what I am doing wrong.

TypeScript version is very old.
Latest version: 4.9.4

To install latest version:

npm install -g typescript@latest

To update to latest:

npm update -g typescript@latest

Let us know!

Dear maverick, now it’s work fine :).
Thank you very much for fast answer.
You gave me the lead, what to looking for.
I couldn’t update tsc until I had remove previous path from system variables.

Even forcing to install the different version (sudo npm i -g typescript@4.6.3), VS Code still is using 2.8.3. I already deleted folder related, restarted my mac but still shows this old version.

And because of that, when I compile I have this error: “error TS2688: Cannot find type definition file for ‘node’.”

Any advice?

Please show us the screenshot of the error in your console along with the node and npm version.
Looks like MacOS (or any version of UNIX)!

Sometimes there is cache issue with npm so try to clear it before updating (installing).

  • clear cache
  • uninstall old version (can update as well instead of uninstall and re-install)

npm cache clean --force
npm un -g typescript
npm i -g typescript@latest

  • to update
    npm update typescript

Note: your CLI may require you to use sudo in front of above commands.

Let us know!

Thanks maverick… all 3 commands works except the update:

11:17:21 fabio@mbp-de-fabio-7: ~/dev/nodejs
$ tsc -v
Version 2.8.3

11:17:51 fabio@mbp-de-fabio-7: ~/dev/nodejs
$ node -v
v19.7.0

11:18:12 fabio@mbp-de-fabio-7: ~/dev/nodejs
$ npm -v
9.6.1

11:18:20 fabio@mbp-de-fabio-7: ~/dev/nodejs
$ sudo npm cache clean --force
npm WARN using --force Recommended protections disabled.

11:18:56 fabio@mbp-de-fabio-7: ~/dev/nodejs
$ sudo npm un -g typescript

removed 1 package in 256ms

11:19:05 fabio@mbp-de-fabio-7: ~/dev/nodejs
$ sudo npm i -g typescript@latest

added 1 package in 3s

11:19:16 fabio@mbp-de-fabio-7: ~/dev/nodejs
$ sudo npm update typescript
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated mkdirp@0.5.1: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
npm ERR! code 1
npm ERR! path /Users/fabio/dev/node_modules/robotjs
npm ERR! command failed
npm ERR! command sh -c prebuild-install || node-gyp rebuild
npm ERR! CXX(target) Release/obj.target/robotjs/src/robotjs.o
npm ERR! sh: /Users/fabio/dev/node_modules/.bin/prebuild-install: Permission denied
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@9.3.1
npm ERR! gyp info using node@19.7.0 | darwin | x64
npm ERR! gyp info find Python using Python version 3.8.2 found at "/Library/Frameworks/Python.framework/Versions/3.8/bin/python3"
npm ERR! gyp info spawn /Library/Frameworks/Python.framework/Versions/3.8/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/Users/fabio/.nvm/versions/node/v19.7.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/fabio/dev/node_modules/robotjs/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/fabio/.nvm/versions/node/v19.7.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/fabio/Library/Caches/node-gyp/19.7.0/include/node/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=/Users/fabio/Library/Caches/node-gyp/19.7.0',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/Users/fabio/.nvm/versions/node/v19.7.0/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/Users/fabio/Library/Caches/node-gyp/19.7.0/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/Users/fabio/dev/node_modules/robotjs',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp info spawn make
npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm ERR! In file included from ../src/robotjs.cc:2:
npm ERR! In file included from ../../nan/nan.h:176:
npm ERR! ../../nan/nan_callbacks.h:55:23: error: no member named 'AccessorSignature' in namespace 'v8'
npm ERR! typedef v8::Local<v8::AccessorSignature> Sig;
npm ERR!                   ~~~~^
npm ERR! In file included from ../src/robotjs.cc:2:
npm ERR! ../../nan/nan.h:2542:8: error: no matching member function for call to 'SetAccessor'
npm ERR!   tpl->SetAccessor(
npm ERR!   ~~~~~^~~~~~~~~~~
npm ERR! /Users/fabio/Library/Caches/node-gyp/19.7.0/include/node/v8-template.h:814:8: note: candidate function not viable: no known conversion from 'imp::Sig' (aka 'int') to 'v8::SideEffectType' for 7th argument
npm ERR!   void SetAccessor(
npm ERR!        ^
npm ERR! /Users/fabio/Library/Caches/node-gyp/19.7.0/include/node/v8-template.h:807:8: note: candidate function not viable: no known conversion from 'imp::NativeGetter' (aka 'void (*)(v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value> &)') to 'v8::AccessorGetterCallback' (aka 'void (*)(Local<v8::String>, const PropertyCallbackInfo<v8::Value> &)') for 2nd argument
npm ERR!   void SetAccessor(
npm ERR!        ^
npm ERR! ../src/robotjs.cc:63:39: error: too few arguments to function call, single argument 'context' was not specified
npm ERR!         const size_t x = info[0]->Int32Value();
npm ERR!                          ~~~~~~~~~~~~~~~~~~~ ^
npm ERR! /Users/fabio/Library/Caches/node-gyp/19.7.0/include/node/v8-value.h:419:3: note: 'Int32Value' declared here
npm ERR!   V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
npm ERR!   ^
npm ERR! /Users/fabio/Library/Caches/node-gyp/19.7.0/include/node/v8config.h:542:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
npm ERR! #define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
npm ERR!                               ^
npm ERR! ../src/robotjs.cc:64:39: error: too few arguments to function call, single argument 'context' was not specified
npm ERR!         const size_t y = info[1]->Int32Value();
npm ERR!                          ~~~~~~~~~~~~~~~~~~~ ^
npm ERR! /Users/fabio/Library/Caches/node-gyp/19.7.0/include/node/v8-value.h:419:3: note: 'Int32Value' declared here
npm ERR!   V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
npm ERR!   ^
npm ERR! /Users/fabio/Library/Caches/node-gyp/19.7.0/include/node/v8config.h:542:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
npm ERR! #define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
npm ERR!                               ^
npm ERR! ../src/robotjs.cc:97:33: error: too few arguments to function call, single argument 'context' was not specified
npm ERR!         size_t x = info[0]->Int32Value();
npm ERR!                    ~~~~~~~~~~~~~~~~~~~ ^
npm ERR! /Users/fabio/Library/Caches/node-gyp/19.7.0/include/node/v8-value.h:419:3: note: 'Int32Value' declared here
npm ERR!   V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
npm ERR!   ^
npm ERR! /Users/fabio/Library/Caches/node-gyp/19.7.0/include/node/v8config.h:542:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
npm ERR! #define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
npm ERR!                               ^
npm ERR! ../src/robotjs.cc:98:33: error: too few arguments to function call, single argument 'context' was not specified
npm ERR!         size_t y = info[1]->Int32Value();
npm ERR!                    ~~~~~~~~~~~~~~~~~~~ ^
npm ERR! /Users/fabio/Library/Caches/node-gyp/19.7.0/include/node/v8-value.h:419:3: note: 'Int32Value' declared here
npm ERR!   V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
npm ERR!   ^
npm ERR! /Users/fabio/Library/Caches/node-gyp/19.7.0/include/node/v8config.h:542:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
npm ERR! #define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
npm ERR!                               ^
npm ERR! ../src/robotjs.cc:114:33: error: too few arguments to function call, single argument 'context' was not specified
npm ERR!         size_t x = info[0]->Int32Value();
npm ERR!                    ~~~~~~~~~~~~~~~~~~~ ^
npm ERR! /Users/fabio/Library/Caches/node-gyp/19.7.0/include/node/v8-value.h:419:3: note: 'Int32Value' declared here
npm ERR!   V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
npm ERR!   ^
npm ERR! /Users/fabio/Library/Caches/node-gyp/19.7.0/include/node/v8config.h:542:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
npm ERR! #define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
npm ERR!                               ^
npm ERR! ../src/robotjs.cc:115:33: error: too few arguments to function call, single argument 'context' was not specified
npm ERR!         size_t y = info[1]->Int32Value();
npm ERR!                    ~~~~~~~~~~~~~~~~~~~ ^
npm ERR! /Users/fabio/Library/Caches/node-gyp/19.7.0/include/node/v8-value.h:419:3: note: 'Int32Value' declared here
npm ERR!   V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
npm ERR!   ^
npm ERR! /Users/fabio/Library/Caches/node-gyp/19.7.0/include/node/v8config.h:542:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
npm ERR! #define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
npm ERR!                               ^
npm ERR! ../src/robotjs.cc:143:48: error: too few arguments to function call, single argument 'context' was not specified
npm ERR!                 v8::String::Utf8Value bstr(info[0]->ToString());
npm ERR!                                            ~~~~~~~~~~~~~~~~~ ^
npm ERR! /Users/fabio/Library/Caches/node-gyp/19.7.0/include/node/v8-value.h:360:3: note: 'ToString' declared here
npm ERR!   V8_WARN_UNUSED_RESULT MaybeLocal<String> ToString(
npm ERR!   ^
npm ERR! /Users/fabio/Library/Caches/node-gyp/19.7.0/include/node/v8config.h:542:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
npm ERR! #define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
npm ERR!                               ^
npm ERR! ../src/robotjs.cc:159:35: error: too few arguments to function call, single argument 'isolate' was not specified
npm ERR!                 doubleC = info[1]->BooleanValue();
npm ERR!                           ~~~~~~~~~~~~~~~~~~~~~ ^
npm ERR! /Users/fabio/Library/Caches/node-gyp/19.7.0/include/node/v8-value.h:408:3: note: 'BooleanValue' declared here
npm ERR!   bool BooleanValue(Isolate* isolate) const;
npm ERR!   ^
npm ERR! ../src/robotjs.cc:239:35: error: too few arguments to function call, single argument 'context' was not specified
npm ERR!         mouseDelay = info[0]->Int32Value();
npm ERR!                      ~~~~~~~~~~~~~~~~~~~ ^
npm ERR! /Users/fabio/Library/Caches/node-gyp/19.7.0/include/node/v8-value.h:419:3: note: 'Int32Value' declared here
npm ERR!   V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
npm ERR!   ^
npm ERR! /Users/fabio/Library/Caches/node-gyp/19.7.0/include/node/v8config.h:542:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
npm ERR! #define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
npm ERR!                               ^
npm ERR! ../src/robotjs.cc:251:30: error: too few arguments to function call, single argument 'context' was not specified
npm ERR!         int x = info[0]->Int32Value();
npm ERR!                 ~~~~~~~~~~~~~~~~~~~ ^
npm ERR! /Users/fabio/Library/Caches/node-gyp/19.7.0/include/node/v8-value.h:419:3: note: 'Int32Value' declared here
npm ERR!   V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
npm ERR!   ^
npm ERR! /Users/fabio/Library/Caches/node-gyp/19.7.0/include/node/v8config.h:542:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
npm ERR! #define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
npm ERR!                               ^
npm ERR! ../src/robotjs.cc:252:30: error: too few arguments to function call, single argument 'context' was not specified
npm ERR!         int y = info[1]->Int32Value();
npm ERR!                 ~~~~~~~~~~~~~~~~~~~ ^
npm ERR! /Users/fabio/Library/Caches/node-gyp/19.7.0/include/node/v8-value.h:419:3: note: 'Int32Value' declared here
npm ERR!   V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
npm ERR!   ^
npm ERR! /Users/fabio/Library/Caches/node-gyp/19.7.0/include/node/v8config.h:542:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
npm ERR! #define V8_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
npm ERR!                               ^
npm ERR! ../src/robotjs.cc:418:44: error: expected '(' for function-style cast or type construction
npm ERR! int GetFlagsFromString(v8::Handle<v8::Value> value, MMKeyFlags* flags)
npm ERR!                                   ~~~~~~~~~^
npm ERR! ../src/robotjs.cc:418:28: error: no member named 'Handle' in namespace 'v8'
npm ERR! int GetFlagsFromString(v8::Handle<v8::Value> value, MMKeyFlags* flags)
npm ERR!                        ~~~~^
npm ERR! ../src/robotjs.cc:418:46: error: use of undeclared identifier 'value'; did you mean 'False'?
npm ERR! int GetFlagsFromString(v8::Handle<v8::Value> value, MMKeyFlags* flags)
npm ERR!                                              ^~~~~
npm ERR!                                              False
npm ERR! /Users/fabio/Library/Caches/node-gyp/19.7.0/include/node/v8-primitive.h:852:26: note: 'False' declared here
npm ERR! V8_INLINE Local<Boolean> False(Isolate* isolate) {
npm ERR!                          ^
npm ERR! ../src/robotjs.cc:418:53: error: unexpected type name 'MMKeyFlags': expected expression
npm ERR! int GetFlagsFromString(v8::Handle<v8::Value> value, MMKeyFlags* flags)
npm ERR!                                                     ^
npm ERR! ../src/robotjs.cc:418:65: error: use of undeclared identifier 'flags'
npm ERR! int GetFlagsFromString(v8::Handle<v8::Value> value, MMKeyFlags* flags)
npm ERR!                                                                 ^
npm ERR! ../src/robotjs.cc:418:71: error: expected ';' after top level declarator
npm ERR! int GetFlagsFromString(v8::Handle<v8::Value> value, MMKeyFlags* flags)
npm ERR!                                                                       ^
npm ERR!                                                                       ;
npm ERR! fatal error: too many errors emitted, stopping now [-ferror-limit=]
npm ERR! 20 errors generated.
npm ERR! make: *** [Release/obj.target/robotjs/src/robotjs.o] Error 1
npm ERR! gyp ERR! build error 
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
npm ERR! gyp ERR! stack     at ChildProcess.onExit (/Users/fabio/.nvm/versions/node/v19.7.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:203:23)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:512:28)
npm ERR! gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:293:12)
npm ERR! gyp ERR! System Darwin 19.6.0
npm ERR! gyp ERR! command "/Users/fabio/.nvm/versions/node/v19.7.0/bin/node" "/Users/fabio/.nvm/versions/node/v19.7.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /Users/fabio/dev/node_modules/robotjs
npm ERR! gyp ERR! node -v v19.7.0
npm ERR! gyp ERR! node-gyp -v v9.3.1
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/fabio/.npm/_logs/2023-03-19T16_19_21_779Z-debug-0.log

After restart VS Code still shows tsc version 2.8.3

Found it! This one was on my bash profile (this is from 2018) =/

alias tsc="~/.npm-packages/bin/tsc"

Thank you!

tsc updated but still have this =/

$ tsc index.ts 
error TS2688: Cannot find type definition file for 'node'.
  The file is in the program because:
    Entry point for implicit type library 'node'


Found 1 error.