Handling version incompatibility in npm dependencies - node.js

Some context
Every time VS Code is released built on a new version of Node, the VS Code Arduino extension breaks until a new version is released.
Having cloned the Arduino extension git repo I uninstalled it as an extension and ran it in the debugger. This worked and now I have specific intel, if only I knew how to act on it. This is the message:
[Warn] no library available after trying files native_loader.js
undefined
Array[3]
0
"d:/vscode-arduino/out/node_modules/node-usb-native/lib/native/detector_darwin_7.1.11_x64.node"
1
"d:/vscode-arduino/out/node_modules/node-usb-native/lib/native/detector_Ubuntu14.04_7.1.11_x64.node"
2
"d:/vscode-arduino/out/node_modules/node-usb-native/lib/native/detector_win32_7.1.11_x64.node"
rejected promise not handled within 1 second: Error: The module '\\?\d:\vscode-arduino\out\node_modules\usb-detection\build\Release\detection.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 80. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
extensionHostProcess.js
stack trace: Error: The module '\\?\d:\vscode-arduino\out\node_modules\usb-detection\build\Release\detection.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 80. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
The last of these files (the Windows x64 one) is indeed present on the expected path so "no library available" doesn't mean it can't find the file. This agrees with the end of the message which reports that no suitable version can be found.
The end of this message suggests npm rebuild or npm i so I tried those to no avail.
Rummaging in package.json revealed
"scripts": {
"vscode:prepublish": "gulp build --mode=production",
"postinstall": "cd ./src/views && npm install && node ../../node_modules/node-usb-native/scripts/rebuild-serialport.js",
"test": "gulp test"
},
"extensionDependencies": [
"ms-vscode.cpptools"
],
"devDependencies": {
"#types/compare-versions": "^3.0.0",
...
"webpack": "^4.44.1"
},
"dependencies": {
...
"node-usb-native": "0.0.13",
...
}
The dependency on node-usb-native is behind the latest (0.0.15). Changing this and running npm i triggers the post-install task to rebuild-serialport.js which appears to succeed, but I get the same error at runtime.
The question
How do I resolve this?
What exactly needs rebuilding? usb-detection isn't listed in the dependencies (or the devDependencies) but if I'm not mistaken node-usb-native depends on it.
How do I go about this such that the code complaining about
versions sees the freshly minted bits?

Related

Failed to compile: Error: Node Sass version 8.0.0 is incompatible with ^4.0.0

I want to make react portfolio from freecodecamp. after all packages installed then change App.css to App.scss and then write some code, then show error like this:
"./src/App.scss (./node_modules/css-loader??ref--6-oneOf-5-1!./node_modules/postcss-loader/src??postcss!./node_modules/sass-loader/lib/loader.js??ref--6-oneOf-5-3!./src/App.scss)
To import Sass files, you first need to install node-sass.
Run `npm install node-sass` or `yarn add node-sass` inside your workspace.
Require stack:
- C:\Tarikul\Projects\portfolio\node_modules\sass-loader\lib\loader.js
- C:\Tarikul\Projects\portfolio\node_modules\loader-runner\lib\loadLoader.js
- C:\Tarikul\Projects\portfolio\node_modules\loader-runner\lib\LoaderRunner.js
- C:\Tarikul\Projects\portfolio\node_modules\webpack\lib\NormalModule.js
- C:\Tarikul\Projects\portfolio\node_modules\webpack\lib\NormalModuleFactory.js
- C:\Tarikul\Projects\portfolio\node_modules\webpack\lib\Compiler.js
- C:\Tarikul\Projects\portfolio\node_modules\webpack\lib\webpack.js
- C:\Tarikul\Projects\portfolio\node_modules\react-scripts\scripts\start.js"
Then install "npm install node-sass":
Then show another error like this: "Error: Node Sass version 8.0.0 is incompatible with ^4.0.0."
I try to "npm install node-sass#4.0.0"
and also try: "npm install node-sass#8.0.0"
but problem is not fixed
Add this to your package.json:
"overrides": {
"node-sass": "^8.0.0",
}
If you are using Node.js 18.x, you need node-sass#8.0.0. Older packages will probably have an older dependency. You can force the dependency, don't worry about compatibility, node-sass is deprecated and hasn't changed in years - except to support newer Node.js versions.

Detox fails with "Cannot find module 'jest-cli/build/cli/args'"

Our CI builds began failing recently with an error like this:
detox test -c android.emu.release
detox[3061] ERROR: [cli.js] Error:
Cannot find module 'jest-cli/build/cli/args'
Locally detox test -c android.emu.release succeeds. Any idea what's wrong?
UPD: ⚠️⚠️⚠️ The workaround below is NOT needed for the recent Detox versions since 17.5.2 and newer. ⚠️⚠️⚠️
For the versions between 17.4.7 and 17.5.1, the following text is historically valid.
If you are seeing an error like the one below:
Cannot find module 'jest-cli/build/cli/args'
You should add jest-cli to your package.json's devDependencies and re-run npm install, e.g.:
"devDependencies": {
"jest": "26.x.x",
+ "jest-cli": "26.x.x",
If you are using a deprecated version of jest (25.x), still make sure that your jest-cli version matches jest's one:
"devDependencies": {
"jest": "^25.5.4",
+ "jest-cli": "^25.5.4",
P. S. Regarding why it is happening. While detox#17.4.7 was not meant to contain any breaking changes, this issue has slipped past the testing lifecycle due to another installation method (via lerna bootstrap instead of the vanilla npm install). Unlike lerna, the current versions of npm would put jest-cli into node_modules/jest/node_modules/jest-cli, that's why Detox is unable to find one, although detox package itself has jest-cli package in the manifest marked as peerDependency, and the relevant warnings are printed:
npm WARN detox#17.4.7 requires a peer of jest-cli#>=25.0.0 but none is installed. You must install peer dependencies yourself.

A dynamic link library (DLL) initialization routine failed in electron with nodegit

When I use nodegit in electron, I got the error when I start the app:
App threw an error during load
Error: A dynamic link library (DLL) initialization routine failed.
\?\D:\Electron\hello\node_modules\nodegit\build\Release\nodegit.node
at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:166:20)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:740:18)
...
I can use nodegit in nodejs successfully, but failed in electron.
Even I added .npmrc file with content below, it's still faield.
runtime = electron
target = 1.2.8
target_arch = x64
disturl = https://atom.io/download/atom-shell
Does anyyone know how to fix it in electron?
My environment is windows 10 x64 with vs 2017, node 10.13, electron 3.010
I had the same problem with another node package using electron 3.0.6 and eventually got it working.
Try these:
Make sure the packages are listed under the dependencies and not devDependencies in the package.json
Add this "electron-rebuild --force node-gyp rebuild --target=3.0.6 --arch=x64" to postinstall under the scripts section. I ended up with this in my packages.json (my DLL error was for "printer")
{
"name": "myproject",
"version": "1.0.0",
"main": "main.js",
"scripts": {
"postinstall": "electron-rebuild --force node-gyp rebuild --target=3.0.6 --arch=x64",
"start": "electron ."
},
"dependencies": {
"#types/node": "^10.12.18",
"electron-rebuild": "1.8.2",
"electron": "3.0.6",
"printer": "0.2.2"
},
"devDependencies": {
...
}
}
See here for more info
Hope this helps someone
From this link:
The most common issue though is that the component was not properly installed, so that some of its dependencies are not available.
First confirm if global node version matches with the project one. Some projects require specific version hence first delete other node and install required node version and project dependencies. Try below solutions to solve the errors as same worked for me
Clean up node modules [ https://medium.com/#mariokandut/how-to-clean-up-node-modules-5aed676156db ] and rebuild the project. It rebuilds node_modules folder
Since it is an electron app try yarn electron-rebuild. For more info on yarn refer " https://www.digitalocean.com/community/tutorials/how-to-install-and-use-the-yarn-package-manager-for-node-js "
If electron rebuild fails check if "Visual C++ Build Environment" are installed. Refer https://stackoverflow.com/a/61252536/9558119 for same.
Rerun electron rebuild and then run build as per your project

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

Laravel with Node.js: "Node Sass could not find a binding for your current environment"

So I did not have installed Node before, just standard Laravel. Today I installed Node.js 8 and now one of my older projects tells me the following in the console:
app.js:66591 Uncaught Error: Module build failed: ModuleBuildError: Module build failed: Error: Missing binding /node_modules/node-sass/vendor/darwin-x64-57/binding.node
Node Sass could not find a binding for your current environment: OS X 64-bit with Node.js 8.x
Found bindings for the following environments:
- OS X 64-bit with Node.js 6.x
This usually happens because your environment has changed since running `npm install`.
Run `npm rebuild node-sass --force` to build the binding for your current environment.
Unfortunately, 'npm rebuild node-sass --force' doesn't change anything. I tried to install either Node 6 or 8, but I cannot get rid of the error (site is still working anyway, is Laravel using Node only for npm?).
So what's the solution for this?

Resources