I managed to compile a custom version of a package using node-gyp on my Windows machine. The build process completed successfully and I have the compiled module sitting in my project folder.
However, when I run npm install
, it completely ignores my locally built version and tries to fetch the package from the npm registry instead. This causes installation failures because the registry version has build issues on Windows.
Is there a way to configure npm to use my pre-built local module rather than attempting to download and compile it again? I’ve tried placing the built files in various locations but npm still tries to build from source every time.
Any suggestions on how to override npm’s default behavior for this specific dependency would be really helpful.
Here’s another method that worked for me with compiled Windows modules: use a .npmrc file in your project root and specify the package name with its local path. This keeps your custom build intact across multiple npm operations without constantly relinking. You can also edit your package-lock.json after installing to point the resolved URLs at your local build folder. It’s not the prettiest fix, but it stops npm from hitting the registry on later installs. Just back up your package-lock.json first - npm might overwrite your edits during major updates.
Try npm link
to fix this. Go to your local module’s folder and run npm link
- this creates a global symlink. Then in your project folder, run npm link <package-name>
to use your local version instead of downloading from npm. You can also edit package.json directly and point to the local path: "package-name": "file:./path/to/your/local/module"
. I’ve found the file path method works better, especially on Windows with custom builds.
you can also copy your built module straight into node_modules after npm install finishes. not elegant but it works every time lol. or bump the version number in your local package.json to be higher than what’s on the registry - npm will think it’s already got the latest version.