After upgrade eslint says NodeJS is undefined - node.js

I have upgraded Eslint from 7.7.0 to 7.10.0 and #types/node from 14.6.0 to 14.11.2. The application tsconfig.json defines types: ["node"] and typescript is version 4.0.3. Eslint is called with eslint --env node,es2020.
Before the upgrade Eslint never flagged any problem in my code. Now Eslint started complaining that NodeJS is not defined in the following code fragment:
private handleServerErrors(error: NodeJS.ErrnoException): void {
if(error.code === "EADDRINUSE") {
. . .
I silence the Eslint error and the compilation succeeded. So seems a problem specific to eslint, not the code.
The same problem happens in another file for namespace JQuery, but I had not yet investigated.
Is there anything I'm missing? Need to add some import? What has changed in eslint/typescript/node?
Thanks for your help!
mario

In my case, #typescript-eslint/parser#4 causes this problem.
Downgrade it to v3 #typescript-eslint/parser#3 to solve the problem.
See: https://github.com/Chatie/eslint-config/issues/45

Related

ESLint needs me to move the function declarations, but where?

I configured eslint js test and installed ESLint add-on for VSC. Now eslint test screaming at me and tells me to move somewhere the function declarations. Could someone tell me where the error is, please?
https://github.com/ewaolczak/javascript-blog/commit/38776188eef93f8cbd40e9de64bf97fa20bd386a?w=1

expo-cli#6.0.6: The engine "node" is incompatible with this module. Expected version ">=12 <=16". Got "18.10.0"

I was running my code about 9 hours ago with no problem. Now, npx react-native run-ios does not work. I figured maybe I needed to run yarn to fix some dependencies, and running yarn got 2/4's through the process before returning the following error...
expo-cli#6.0.6: The engine "node" is incompatible with this module. Expected version ">=12 <=16". Got "18.10.0"
Now I understand what this is telling me, that the expo-cli dependency needs a node version between 12.0.0 and 16.0.0, but I'm slightly taken aback by this, the only way that makes sense to me is if the expo-cli literally updated yesterday night.
I added the following to my package.json in hopes to mitigate the error to no avail...
"engines" : {
"node" : "<=16.0.0"
},
Do I need to downgrade / upgrade the expo-cli? I'm using bare RN but with expo modules appended to it
Weird issue, I restarted my machine and the error disappeared entirely. Hopefully this doesn't happen again or if it does, its as easily fixable

Testing expo with enzyme: jest-environment-enzyme does not export getVmContext

I'd like to use enzyme to test my React-Native components in Expo managed project.
I follow the docs for jest-expo-enzyme, but now I get:
Test environment found at "/Users/raarts/myproject/node_modules/jest-environment-enzyme/lib/index.js" does not export a "getVmContext" method, which is mandatory from Jest 27. This method is a replacement for "runScript".
My guess from here is that jest-environment-enzyme (last release 2 years ago), somehow needs to be updated for jest 27, but given jest-expo-enzyme was released 2 months ago, I figured I must be doing something wrong. Clueless on how to proceed.
Anybody has any advice?
This is a bug in enzyme. A workaround is provided in this comment.
The solution is to force upgrade jest-environment-jsdom package.
The better way to do it is via resolutions, if you are using Yarn, add this to your package.json:
"resolutions": {
"jest-environment-jsdom": "27.4.6"
},
Check for the latest version of jest-environment-jsdom and change it if necessary.
You can also do this in classic NPM using the npm-force-resolutions package.
Note: you may encounter other problems after fixing this one, if you get a setImmediate error see this comment
I am working on Next js project and using Jest and enzyme for testing, and for me I was able to fix this error by changing
testEnvironment: 'enzyme',
to
testEnvironment: 'jsdom',
in jest.config.js file.

Angular build - Module not found: Error: Can't resolve 'console'

I have a problem with my Angular project build, and ultimately deployment to heroku. I'm using an old(ish) npm package called binary parser, which causes the following error on when I build / deploy to heroku:
Module not found: Error: Can't resolve 'console' in '/tmp/build_e75b87f248f44978f9537d83b3172254/node_modules/binary-parser/dist'
The binary-parser.js has a line require("console"); which is used in exactly one place, so local builds succeed and the application works perfectly, if only I remove console from that line altogether. But as, heroku installs node modules when deploying, this only helps when I manually build the prod version.
I have installed typings for binary-parser and for TS, and also included "types": ["node"] in both tsconfig.json and tsconfig.app.json compilerOptions.
As angular these days doesn't really allow for webpack configuration, I've tried adding global.console = global.console || require('console-browserify');
(or)
global.console = global.console || require('console');
to my polyfills, to no avail.
Any ideas on how to solve this? Do I need to configure a custom webpack to circumvent this? I'll gladly post additional information if necessary!
Here's a possible cause, may or may not be what you or others reading this question are experiencing...
My IDE's auto importing added import * as console from "console"; when I typed console.log.
Solution was of course to remove that import statement.
After trying for multiple hours to come up with the right configuration, the only solution I could come up with was forking the repo in question and changing tsconfig target from es5 to es6, which got rid of the console import altogether upon compilation.

Error: Cannot resolve module 'apply' webpack angular2

I am not really sure how I got into this pickle.. I uninstalled my global webpack and reinstalled it locally to dockerize my project. Then I got a trail of errors, resolved the ones I could and I'm left with this
http://puu.sh/orazd/b8a85ac5c6.png
I don't use any module called apply, most certainly not in every file
I had tried resolveLoader previously
and it had worked for me.
My configuration is as follows:
resolveLoader: {
modulesDirectories: [
'/users/path/a/node_modules'
]
},
Hope this helps.
Though not sure, I think maybe something wrong, like conflicts, in the typings folder. Would you try to remove typings folder and run npm install again.
The answer turned out to be
silly enough.. the error was a little misleading but.

Resources