How can I force node to download packages for a specific architecture? - npm-install

Context on my setup:
I am using Mac M1 and am running windows through parallels.
When running npm install the default package that is being downloaded is ia32 architecture and as far as I know parallels does not support x64 windows however x64 programs can be run on the ia32 architecture with no issues.
The package I am trying to download is from a custom repository and has no ia32 package build.
I am aware of commands such as npm install --arch=x64 and this works great however I am trying to bootstrap using lerna and would like to override the downloading dependencies step in lerna to use x64 packages
Is there a way to force node to install x64 packages through modifying the package.json or through another means?

Related

How do I check that my npm package is installable on all the Node versions and platforms I want to support?

I publish an npm package that uses C++ code using nan. How can I double check that my package can be installed/imported on Linux, macOS and Windows with Node 14+ after I run npm publish?

How to build Prisma Windows electron app on Linux?

What we want to achieve is to build linux and windows installers for our Electron app on our (Linux) build server.
After installing Wine, this basically works, except for Prisma:
i.e. Prisma relies on OS-specific binaries - thus, we must have the correct binaries available for each platform.
Prisma Query engine / Prisma Client
This part works: we set the binaryTarget to our target platforms: binaryTargets = ["windows", "debian-openssl-1.1.x"].
When we now generate the client (prisma generate), the target dir (node_modules/.prisma/client/) contains the query-engines for linux and windows: libquery_engine-debian-openssl-1.1.x.so.node, query_engine-windows.dll.node
Prisma Migration Engine
i.e. in package.json we only specify the prisma dependency and npm will only install the binaries for the current OS in node_modules/#prisma/engines/, i.e.: libquery_engine-debian-openssl-1.1.x.so.node, migration-engine-debian-openssl-1.1.x
How can we get npm to install both migration Engines (i.e. for Windows and Linux)?
set the PRISMA_CLI_BINARY_TARGETS accordingly: e.g. PRISMA_CLI_BINARY_TARGETS=darwin,rhel-openssl-1.0.x npm install
then start npm install
and now the binaries for all specified operating systems should exist in node_modules/#prisma/engines
in my case, this did not work initially
after deleting node_modules/#prisma/engines and starting npm install again, it worked

Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime (93)

this what VSC terminal show me
Error: Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime (93)
For more information on which environments are supported please see:
https://github.com/sass/node-sass/releases/tag/v4.14.1
i tried some solutions in stack overflow:
npm rebuild node-sass
and
npm uninstall node-sass && npm install node-sass
but does't work with , i saw some people talk about node version if support sass or not,
im using v16.14.0 it's LTS version should that support i guess,
i hope someone can help and THANK YOU
It's almost like it's trying to install the 4.x branch which only supports up to Node 14.
Try installing the 7.0.1 (current latest).
npm i node-sass#7.0.1
I'd recommend going ahead and wiping node_modules prior to installing just to be safe.
If that doesn't work, can you please post the entire output in the comment?
Fix the errors due to node-sass:
1. Remove "sass" and "sass-loader" from package.json
2. rm -rf node_modules
3. npm install
4. npm install sass --save-dev
5. npm install sass-loader --save-dev
The versions of some packages is enforced in package.json. The solution is to re-add them by letting npm to establish their right version for your OS.
I fixed this issue by forcing Visual Studio to use the node version I installed instead of VS installed version of node:
Go to Visual Studio, Tools -> Options, Project and Solutions -> Web Package Management -> External Web Tools, and move the $(PATH) to the second place below .\node_modules\.bin and above $(VSInstalledExternalTools). Restart Visual Studio.
Found this solution here.

Apache Cordova VS Community 2015 - Run Dependency Checker Fails

Apache Cordova Dependency Checker fails in VS Community 2015. It was previously working on this computer until I ran several VS and 3rd party tools updates. Here's what I've done to try to resolve the issue:
Installed VS / Apache Cordova (no error messages displayed) following article https://taco.visualstudio.com/en-us/docs/install-vs-tools-apache-cordova/
Run Apache Cordova Dependency Checker but VS freezes with the error message - VS 2015 has stopped working, windows will try to restart the program.
I restarted VS and cleared Cordova cache, checked environment variables (all good), then tried Apache Cordova Dependency Checker with the same freeze result.
I tried to update Apache Cordova with the fix option (no error messages) but received the same freeze results.
I completely uninstalled Apache Cordova, 3rd party tools (following article https://support.microsoft.com/en-us/kb/3016536), and VS community and then reinstalled them (no error messages) but received the same freeze results.
I installed Apache Cordova on another computer and the dependency checker phonegap app... worked. Unfortunately that's not a computer that I have access to.
What else can I do to resolve the Apache Cordova installation issue?
Thanks for any help,
Mike
Since my original post, I've had to resolve Visual Studio, Ionic, Cordova, Phonegap, plugin... environment issue several times. I've found the below works best:
Ensure platform matches plugin requirements, see platform in config.xml e.g. 6.1.1
Uninstall, reinstall latest jdk (adobe)
Clear MEF Cache - download the tool and follow instructions
Download/install latest node.js
Run the following from the command line:
Clear cache: Npm cache clean
Install latest npm: npm install -g npm
Uninstall cordova: Npm uninstall -g cordova
Reinstall cordova: Npm install –g cordova (note, this took 5+ tries to complete without errors. No other changes were made between runs. Not sure
why. Found others complaining about the same issue.)
Remove Android platform: Cordova platform remove android
Install Cordova platform add android#6.X.X (Note, as of 4/20/17 cordova and android compatibility issue. Build error - unable to find installed version of gradle. resolved by running (npm install -g cordova#6.4.0) and (cordova platform add android#6.1.2). Addt'l build errors, resolved by updating components in Android SDK Manager)
Uninstall/Reinstall plugins from the command line. For example:
cordova plugin remove phonegap-plugin-push
cordova plugin add phonegap-plugin-push variable SENDER_ID="YourID#"
npm install bower -g
Restart Visual Studio - Verify plugins were installed via config.xml
Install Ionic:
npm uninstall -g ionic
npm install -g ionic (note: to install specific version, npm install -g ionic#2.2.3)
$ ionic platform add ios
$ ionic platform add android (note: redundant, already added above)
I recommend putting as much of this as possible in a batch file with a pause between commands. Verify each command was successful, if not press ctrl+break at the pause to term the batch file early. The batch file is an easy way to restore your environment when everything breaks again. Stuff happens!
I also started using a VM (oracle virtualbox) for my development environment. That way I can backup my environment before making changes and easily restore. Don't forget to upload to GIT on a daily basis. GIT and VMs are my lifesavers.
Cool NPM commands:
npm list (lists all installed packages)
npm prune (removes packages not depended on by your project according to your package.json)
npm outdated (tells you which installed packages are outdated with respect to what is current in the npm registry but allowable by the version definition in your package.json. Make sure all up-to-date)
Please feel free to add/make suggestions to the above list.
-Mike

Installing node.js packages for different architecture

I need to install npm packages that are for a different target architecture (Linux x64) than the machine I am running npm from (Windows x86). Is there a way to tell npm install to download packages that are for the other OS/architecture?
Most native node modules use node-pre-gyp which uses an install script to search for pre-built binaries for your OS/arch/v8 ABI combination, and fallback to native build if one is not available.
Assuming your native modules use node-pre-gyp, you can do this:
npm i --target_arch=x64 --target_platform=linux
You'll see something like this in the output:
> bcrypt#1.0.3 install /home/user/myProject/node_modules/bcrypt
> node-pre-gyp install --fallback-to-build
[bcrypt] Success: "/home/user/myProject/node_modules/bcrypt/lib/binding/bcrypt_lib.node" is installed via remote
If it can't find a prebuilt binary, node-pre-gyp will fall back to attempting to build the module from source.
If the prebuilt modules aren't downloadable, there's also a way to build & host them from your own mirror, but that's a different question :)
Most binary npm packages compile the .node binary from source. You can't really force cross-compilation with npm, but you can possibly create a postinstall script to recompile the particular dependency that re-runs node-gyp with an --arch flag:
"postinstall" : "node-gyp -C node_modules/your-dependency clean configure --arch=x86_64 rebuild"
You will need a proper compiler toolchain. I'm sot sure what it is for windows, but probably you'll end up using mingw or cygwin
In case the package is electron, you can by
npm install --arch=x64 electron
or
export npm_config_arch=x64
npm install --arch=x64 electron
as described on https://www.electronjs.org/docs/latest/tutorial/installation.
These are options of the electron-download package which downloads the actual binary. So they will work only for electron.