How to fix tsc throwing errors for node typings? - typescript-typings

I have started a new node project using typescript.
I installed typescript via:
$ npm install typescript#2 -g
My enviornment looks like this:
$ tsc -v
Version 2.0.0
$ node -v
v7.10.0
I installed the typings for node via:
npm install --save #types/node
I would expect:
tsc
to just run through without errors. Instead, I get errors in regards to the typings themselves:
366 isTTY?: true;
~~~~
node_modules/#types/node/index.d.ts(366,17): error TS1110: Type expected.
1907 all?: false;
~~~~~
node_modules/#types/node/index.d.ts(1907,15): error TS1110: Type expected.
1911 all: true;
~~~~
node_modules/#types/node/index.d.ts(1911,14): error TS1110: Type expected.
1930 ttl: true;
~~~~
node_modules/#types/node/index.d.ts(1930,14): error TS1110: Type expected.
4138 type DoesZapCodeSpaceFlag = 0 | 1;
~
node_modules/#types/node/index.d.ts(4138,33): error TS1110: Type expected.
My typescript will transpile anyways, yet I rather fix these errors. How to fix them?

I was using an outdated tsc version. You may check if this is a problem via:
$ which tsc
/usr/local/bin/tsc
And it wasn't being updated by "npm install typescript -g" as those got installed to a path relative to my nvm.
Instead, I now use a local version of typescript for the project via:
npm install typescript --save
that will store the executable to:
$ ./node_modules/typescript/bin/tsc -v
Version 2.3.2
npm scripts looks for local binaries per default, hence I added the script in the package.json:
"scripts": {
"console": "tsc && node dist/console.js",
},
so I can run just:
npm run console

Related

npx create-react-app -> The engine "node" is incompatible with this module. Expected version ">= 10.x". Got "8.16.0" - Arch Linux

I know this has been here many times, but it just doesn't work. I use Arch Linux. Everytime I try to run
npx create-react-app my-app
or
npm create-react-app my-app
I get
error #pmmmwh/react-refresh-webpack-plugin#0.4.3: The engine "node" is incompatible with
this module. Expected version ">= 10.x". Got "8.16.0"
error Found incompatible module.
When I type node -v I get 14.16.1 and npm -v -> 7.10.0
Looks like the node version doesn't appear update to 14.x version. Maybe?
I have tried updating sudo npm install -g npm and sudo n stable.
When I try sudo npm install npm#latest -g I get a lot of Missing write access to /usr/local/lib/node_modules/.............
The fix was that I had installed node via pacman and via Snap Store (I didn't know about it) and I saw in WebStorm that there is some node v 8.16.0 installed. So i uninstalled the snap version and it's working. Looks like create-react-app was using the snap version

Error during migration from npm to yarn - The engine "node" is incompatible with this module

in my project I am trying to migrate from npm to yarn.
I simply ran the "yarn" command to generate the "yarn.lock".
During the process, it showed me the following error:
error linearicons#1.0.2: The engine "node" is incompatible with this module.
Expected version "^12.13.0". Got "10.19.0" error Found incompatible module.
So I ran the command "npm remove linearicons" then "yarn" to generate the "yarn.lock" without error, then "yarn add linearicons". But it gives me the same error as above.
My Yarn version is 1.22.10
Node version : v10.19.0
What could I do to fix this problem? I don't understand what he wants
Update the node.js version :
Installation of nvm
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
$ source ~/.bashrc
Looking for existent versions of node.js
$ nvm ls-remote
Installation of the last one (as of today)
$ nvm install v16.8.0
After that your issue should be fixed.
yarn install --ignore-engines
This worked for me, and it was showing this error:
webpack-dev-server#4.5.0: The engine "node" is incompatible with this module. Expected version ">= 12.13.0". Got "10.19.0"
Final result after --ignore-engines
success Saved lockfile.

The engine "node" is incompatible with this module. Expected version "12.x". Got "14.8.0"

I try to do a yarn add, but I have this error:
The engine "node" is incompatible with this module. Expected version "12.x". Got "14.8.0"
Run these commands:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
Then in your project directory run:
rm -r ./node_modules
rm ./yarn.lock
After this, yarn install | add | upgrade should work as expected.
P.S. If you are using the npm package manager, instead of rm ./yarn.lock run rm ./package-lock.json.
One time fix for the "the engine node is incompatible with this module" problem.
$ yarn install --ignore-engines
I can suggest 2 solutions :
1/ It works but it's probably not the best way
You just have to update your packages.json.
currently :
"engines": {
"node": "12.x"
}
updated :
"engines": {
"node": "14.8.0"
}
2/ I think it's a cleaner way
You can use nvm use x to use the Node version.
exemple : nvm use 14 to use node version 14
I had the same problem when I try to make a new app with react. When I do npx create-react-app my-app,
I get this error:
babel-jest#27.4.5: the engine "node" is incompatible with this module. expected version "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0". got "14.8.0"
I solved this problem with this which I found this on other stockoverflow answer.
I can't install react using npx create-react-app?
npm install -g create-react-app
This may help you.

Typescript is not removed even after reinstalling node

While working on Angular 5 project, I got the following error on compilation :
#angular/compiler-cli#5.2.11 requires typescript#'>=2.4.2 <2.7.0' but 2.7.2 was found instead.
Using this version can result in undefined behaviour and difficult to debug problems.
Please run the following command to install a compatible version of TypeScript.
npm install typescript#'>=2.4.2 <2.7.0'
To disable this warning run "ng set warnings.typescriptMismatch=false".
To fix this error did the following:
Deleted all node_module instances, and uninstalled node from control panel -> add/remove programs.
Reinstalled node
Checked in cmd:npm view typescript version
I received version as 3.2.2
npm uninstall -g typescript
npm cache verify
Still typescript is not removed from npm.
Can some one help me uninstall typescript completely? Been stuck on this for 2 days now.
It seems there is a small mistake in compiler log:
Please run the following command to install a compatible version of TypeScript.
npm install typescript#'>=2.4.2 <2.7.0'
should be
npm install typescript#">=2.4.2 <2.7.0"
Maybe there is a mismatch in your package json. Update the typescript version as suggested and update package.json
run:
npm install typescript#'>=2.4.2 <2.7.0' --save
Check following step:
You call #angular/compiler-cli in global or local(just one folder), you need install typescript same.
Install typescript match '>=2.4.2 <2.7.0', example : typescript#2.6.2, local or global with -g.
Try close your cmd, reopen it (if typescript install global, cmd don't know it change if you don't reopen).
Check your eviroment variable NODE_PATH, if it exist, go to that folder to remove module in that.
To check NODE_PATH, type in your cmd : echo %NODE_PATH%

LevelDOWN: NODE_MODULE_VERSION error when testing, but not running

I have a .npmrc file with:
runtime = electron
target = 1.7.9
target_arch = x64
disturl = https://atom.io/download/atom-shell
build_from_source = true
And apackage.json file with:
"scripts": {
"start": "electron .",
"test": "mocha"
}
Following a npm install, when I run my node.js script using npm start, everything works as expected. However, when I use npm test I'm running into an error:
Uncaught LevelUPError: Failed to require LevelDOWN (The module '/Users/_me_/_project_/node_modules/leveldown/build/Release/leveldown.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 54. This version of Node.js requires
NODE_MODULE_VERSION 57. Please try re-compiling or re-installing
the module (for instance, using 'npm rebuild' or 'npm install').). Try 'npm install leveldown' if it's missing
My test.js file uses a small subset of modules that do not require electron.
I've tried running npm rebuild, npm install, and npm install leveldown after clearing the npm_modules directory, but the error persists.
Any idea why I'm seeing these errors or how to correct this issue?
Edit: I was able to switch mocha out with electron-mocha and bypass the error.
npm cache clean
npm install
electron-rebuild(need npm install electron-rebuild)
i ues these methods to solve the problem

Resources