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

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?

Related

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

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?

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.

Gulp sass returning Error: python2 not found

This is what I see when I try to install gulp-sass like this:
npm i gulp-sass --save-dev
Running gulp-watch and gulp browser-sync works
TIA
As the error message suggests you probably don't have python installed. The node-sass library compiles the libsass from source. For that it uses node-gyp. To build under windows the readme suggests:
On Windows
Option 1
Install all the required tools and configurations using Microsoft's windows-build-tools using npm install --global --production windows-build-tools from an elevated PowerShell or CMD.exe (run as Administrator).
Option 2
Install tools and configuration manually:
Install Visual C++ Build Environment: Visual Studio Build Tools (using "Visual C++ build tools" workload) or Visual Studio 2017 Community (using the "Desktop development with C++" workload)
Install Python 2.7 (v3.x.x is not supported), and run npm config set python python2.7 (or see below for further instructions on specifying the proper Python version and path.)
Launch cmd, npm config set msvs_version 2017
If the above steps didn't work for you, please visit Microsoft's Node.js Guidelines for Windows for additional tips.
If you have multiple Python versions installed, you can identify which Python version node-gyp uses by setting the '--python' variable:
node-gyp --python /path/to/python2.7
If node-gyp is called by way of npm and you have multiple versions of Python installed, then you can set npm's 'python' config key to the appropriate value:
npm config set python /path/to/executable/python2.7

React-Native Install Error

ling react-native I get the following error (on windows)
C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\src\win_delay_load_hook.c(31):
error C2373: '__pfnDliNotifyHook2': redefinition; different type modifiers
[C:\Projects\JustEatLife\node_modules\react-native\node_modules\ws
\node_modules\bufferutil\build\bufferutil.vcxproj]
I've installed windows sdks, added the C++ tools to my VS 2015 installation, installed android studio, java etc.
Is there any way to resolve this?
I got same problem, and for me the answer was to update node-gyb from version 3.3.1 to 3.4.0 in npm.
For instructions how to do it, see:
npm install fails with error C2373 with vs2015 update 3
If npm i fails, try npm install node-gyp after you have updated version number in packages.json

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.