Same problem here
npm WARN deprecated natives@1.1.6: This module relies on Node.js's internals and will break at some point. Do not use it, and update to graceful-fs@4.x.
npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
npm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated json3@3.3.2: Please use the native JSON object instead of JSON 3
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated gulp-header@1.8.9: Removed event-stream from gulp-header
npm WARN deprecated chokidar@1.7.0: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated cryptiles@2.0.5: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).
npm WARN deprecated graceful-fs@1.2.3: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated boom@2.10.1: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).
npm WARN deprecated minimatch@0.2.14: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated sntp@1.0.9: This module moved to @hapi/sntp. Please make sure to switch over as this distribution is no longer supported and may contain bugs and critical security issues.
npm WARN deprecated formidable@1.0.17: Please upgrade to latest, formidable@v2 or formidable@v3! Check these notes: https://bit.ly/2ZEqIau
npm WARN deprecated gulp-util@3.0.8: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
npm WARN deprecated hoek@2.16.3: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).
npm WARN deprecated request@2.81.0: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated mkdirp@0.3.0: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@4.2.1: this library is no longer supported
npm WARN deprecated express@2.5.11: express 2.x series is deprecated
npm WARN deprecated hawk@3.1.3: This module moved to @hapi/hawk. Please make sure to switch over as this distribution is no longer supported and may contain bugs and critical security issues.
npm WARN deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
npm WARN deprecated popper.js@1.16.1: You can find the new Popper v2 at @popperjs/core, this package is dedicated to the legacy v1
npm WARN deprecated connect@1.9.2: connect 1.x series is deprecated
npm WARN cleanup Failed to remove some directories [
npm WARN cleanup [
npm WARN cleanup 'I:\Kivitelezes\PeterBurgerEU\Tarhely\gulpteszt\resume-bootstrap4-master\node_modules\glob-watcher\node_modules',
npm WARN cleanup [Error: EPERM: operation not permitted, rmdir 'I:KivitelezesPeterBurgerEUTarhelygulptesztresume-bootstrap4-masternode_modulesglob-watchernode_modulesglobuletestfixturesexpanddeep'] {
npm WARN cleanup errno: -4048,
npm WARN cleanup code: 'EPERM',
npm WARN cleanup syscall: 'rmdir',
npm WARN cleanup path: 'I:\Kivitelezes\PeterBurgerEU\Tarhely\gulpteszt\resume-bootstrap4-master\node_modules\glob-watcher\node_modules\globule\test\fixtures\expand\deep'
npm WARN cleanup }
npm WARN cleanup ],
npm WARN cleanup [
npm WARN cleanup 'I:\Kivitelezes\PeterBurgerEU\Tarhely\gulpteszt\resume-bootstrap4-master\node_modules\glob-watcher',
npm WARN cleanup [Error: EPERM: operation not permitted, rmdir 'I:KivitelezesPeterBurgerEUTarhelygulptesztresume-bootstrap4-masternode_modulesglob-watchernode_modulesglobuletestfixturesexpanddeep'] {
npm WARN cleanup errno: -4048,
npm WARN cleanup code: 'EPERM',
npm WARN cleanup syscall: 'rmdir',
npm WARN cleanup path: 'I:\Kivitelezes\PeterBurgerEU\Tarhely\gulpteszt\resume-bootstrap4-master\node_modules\glob-watcher\node_modules\globule\test\fixtures\expand\deep'
npm WARN cleanup }
npm WARN cleanup ]
npm WARN cleanup ]
npm ERR! code 1
npm ERR! path I:KivitelezesPeterBurgerEUTarhelygulptesztresume-bootstrap4-masternode_modulesnode-sass
npm ERR! command failed
npm ERR! command C:WINDOWSsystem32cmd.exe /d /s /c node scripts/build.js
npm ERR! Building: C:Program Filesnodejsnode.exe I:KivitelezesPeterBurgerEUTarhelygulptesztresume-bootstrap4-masternode_modulesnode-gypbinnode-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp verb cli [
npm ERR! gyp verb cli 'C:\Program Files\nodejs\node.exe',
npm ERR! gyp verb cli 'I:\Kivitelezes\PeterBurgerEU\Tarhely\gulpteszt\resume-bootstrap4-master\node_modules\node-gyp\bin\node-gyp.js',
npm ERR! gyp verb cli 'rebuild',
npm ERR! gyp verb cli '--verbose',
npm ERR! gyp verb cli '--libsass_ext=',
npm ERR! gyp verb cli '--libsass_cflags=',
npm ERR! gyp verb cli '--libsass_ldflags=',
npm ERR! gyp verb cli '--libsass_library='
npm ERR! gyp verb cli ]
npm ERR! gyp info using node-gyp@3.8.0
npm ERR! gyp info using node@18.12.1 | win32 | x64
npm ERR! gyp verb command rebuild []
npm ERR! gyp verb command clean []
npm ERR! gyp verb clean removing "build" directory
npm ERR! gyp verb command configure []
npm ERR! gyp verb check python checking for Python executable "python2" in the PATH
npm ERR! gyp verb `which` failed Error: not found: python2
npm ERR! gyp verb `which` failed at getNotFoundError (I:KivitelezesPeterBurgerEUTarhelygulptesztresume-bootstrap4-masternode_moduleswhichwhich.js:13:12)
npm ERR! gyp verb `which` failed at F (I:KivitelezesPeterBurgerEUTarhelygulptesztresume-bootstrap4-masternode_moduleswhichwhich.js:68:19)
npm ERR! gyp verb `which` failed at E (I:KivitelezesPeterBurgerEUTarhelygulptesztresume-bootstrap4-masternode_moduleswhichwhich.js:80:29)
npm ERR! gyp verb `which` failed at I:KivitelezesPeterBurgerEUTarhelygulptesztresume-bootstrap4-masternode_moduleswhichwhich.js:89:16
npm ERR! gyp verb `which` failed at I:KivitelezesPeterBurgerEUTarhelygulptesztresume-bootstrap4-masternode_modulesisexeindex.js:42:5
npm ERR! gyp verb `which` failed at I:KivitelezesPeterBurgerEUTarhelygulptesztresume-bootstrap4-masternode_modulesisexewindows.js:36:5
npm ERR! gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:207:21)
npm ERR! gyp verb `which` failed python2 Error: not found: python2
npm ERR! gyp verb `which` failed at getNotFoundError (I:KivitelezesPeterBurgerEUTarhelygulptesztresume-bootstrap4-masternode_moduleswhichwhich.js:13:12)
npm ERR! gyp verb `which` failed at F (I:KivitelezesPeterBurgerEUTarhelygulptesztresume-bootstrap4-masternode_moduleswhichwhich.js:68:19)
npm ERR! gyp verb `which` failed at E (I:KivitelezesPeterBurgerEUTarhelygulptesztresume-bootstrap4-masternode_moduleswhichwhich.js:80:29)
npm ERR! gyp verb `which` failed at I:KivitelezesPeterBurgerEUTarhelygulptesztresume-bootstrap4-masternode_moduleswhichwhich.js:89:16
npm ERR! gyp verb `which` failed at I:KivitelezesPeterBurgerEUTarhelygulptesztresume-bootstrap4-masternode_modulesisexeindex.js:42:5
npm ERR! gyp verb `which` failed at I:KivitelezesPeterBurgerEUTarhelygulptesztresume-bootstrap4-masternode_modulesisexewindows.js:36:5
npm ERR! gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:207:21) {
npm ERR! gyp verb `which` failed code: 'ENOENT'
npm ERR! gyp verb `which` failed }
npm ERR! gyp verb check python checking for Python executable "python" in the PATH
npm ERR! gyp verb `which` succeeded python C:Python311python.EXE
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Command failed: C:Python311python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
npm ERR! gyp ERR! stack File "<string>", line 1
npm ERR! gyp ERR! stack import sys; print "%s.%s.%s" % sys.version_info[:3];
npm ERR! gyp ERR! stack ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
npm ERR! gyp ERR! stack SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
npm ERR! gyp ERR! stack
npm ERR! gyp ERR! stack at ChildProcess.exithandler (node:child_process:412:12)
npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:513:28)
npm ERR! gyp ERR! stack at maybeClose (node:internal/child_process:1091:16)
npm ERR! gyp ERR! stack at Socket.<anonymous> (node:internal/child_process:449:11)
npm ERR! gyp ERR! stack at Socket.emit (node:events:513:28)
npm ERR! gyp ERR! stack at Pipe.<anonymous> (node:net:313:12)
npm ERR! gyp ERR! System Windows_NT 10.0.19044
npm ERR! gyp ERR! command "C:\Program Files\nodejs\node.exe" "I:\Kivitelezes\PeterBurgerEU\Tarhely\gulpteszt\resume-bootstrap4-master\node_modules\node-gyp\bin\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm ERR! gyp ERR! cwd I:KivitelezesPeterBurgerEUTarhelygulptesztresume-bootstrap4-masternode_modulesnode-sass
npm ERR! gyp ERR! node -v v18.12.1
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok
npm ERR! Build failed with error code: 1
npm ERR! A complete log of this run can be found in:
npm ERR! C:UsersBeciAppDataLocalnpm-cache_logs2022-11-10T16_25_40_106Z-debug-0.log
It’s a common practice using node.js for front-end app development. In the Windows dev environment, the same exercise applies. If you use Windows Subsystem for Linux (WSL), you can make use of the Linux environment for it. But what if you want to keep your dev environment on Windows 11? One of the most infamous errors you might be able to see is related to the node-gyp
package. Throughout this post, I’m going to discuss how to fix the node-gyp
error on Windows 11.
node-gyp
Package Dependencies
The node-gyp
package is a part of npm, which is automatically installed while installing node.js. Therefore, you should be aware of your node.js and npm versions to get the issue sorted out. The latest LTS version of node.js at the time of this writing is 16.13.0
and npm of 8.1.0
.
In general, if there’s a project on GitHub you are collaborating on, what could be the process to build an app?
- Clone the repository to your local dev environment,
- Run the
npm install
command to download node modules, and - Run the
npm run <command>
command to run the application
I know the steps identified above are exactly the same but similar. Depending on your case, you might use the node-gyp
package, which you are likely to meet the errors below.
Python
It doesn’t matter whether you are developing Python apps or not. The node-gyp
package has a direct dependency on Python, and you have to install it beforehand.
You might see the error message like below while running the command, npm install
.
NOTE: The default version of
node-gyp
is8.2.0
, which comes with node.js (LTS)14.13.0
, as the screenshot says.
It’s because Python is not installed on your machine. The solution is straightforward – install Python. Go to the Python website, download the latest version and install it. The newest version of Python at the time of this writing is 3.10.0
.
Once installed, run the following command to check whether Python is correctly installed or not.
Visual Studio 2019 Build Tools
Run the npm install
command again. Then, you’ll see the following error.
The node-gyp
package also depends on the C++ compiler, and your dev environment doesn’t have it yet. Therefore, you can install Visual Studio or Standalone Build Tools. In this section, let’s use the Standalone Build Tools for now. While installing, choose the «Desktop development with C++» workload option.
Since the download link currently offers the Visual Studio 2019 version at the time of this writing, you will be able to see the following screen after the installation.
The installed path is the following:
C:Program Files (x86)Microsoft Visual Studio2019BuildTools
Run the npm install
command again. Then you’ll get all the node modules installed with no error. However, if you still see the error like above, you should let npm know the version of Visual Studio like:
npm config set msvs_version 2019
Then, everything will go alright with the npm install
command.
NOTE: Depending on the timing, the Standalone Build Tools download link offers you the latest version of Build Tools. Therefore, you might not download Visual Studio 2019 version but the later version. If you download the later version than Visual Studio 2019, try the following section.
Visual Studio 2022 Build Tools
Recently, Visual Studio 2022 was released, and the Build Tool has also been upgraded to 2022. This page gives you the latest release of Build Tools. Choose the «Desktop development with C++» workload option, like before.
The installed location looks like this:
C:Program Files (x86)Microsoft Visual Studio2022BuildTools
But the node-gyp
version that comes with node.js 14.13.0
doesn’t support Visual Studio 2022. Therefore, you should update the npm version by running the following command:
npm install -g npm
Once updated, the npm version is changed from 8.1.0
to 8.1.4
.
In addition to that, the node-gyp
package also has been updated from 8.2.0
to 8.4.0
.
Now, run the npm install
command again, and it will properly install all the node modules. You can also override the Visual Studio version like:
npm config set msvs_version 2022
Visual Studio 2022
In the previous two cases, you don’t need to install Visual Studio but the Build Tools workload. This time, let’s use Visual Studio 2022 itself. Visual Studio 2022 has a different installed location because it’s now running on the x64 mode natively.
C:Program FilesMicrosoft Visual Studio2022Community
Your node-gyp
version has already been updated to 8.4.0
. Hence, once you complete installing Visual Studio 2022, running the npm install
command won’t cause an issue. Then, of course, you can force the Visual Studio version like below:
npm config set msvs_version 2022
NOTE: In this post, I just use the Visual Studio Community Edition. But you can use Professional or Enterprise Edition.
Long Path Issue
It’s not related to the node-gyp
package, but you will frequently see this issue while developing the node.js app on Windows. The long path issue on Windows OS is now resolved on Windows 11 through Local Group Policy Editor.
Once open Local Group Policy Editor, navigate to «Local Computer Policy» ➡️ «Computer Configuration» ➡️ «Administrative Templates» ➡️ «System» ➡️ «File System» and open the «Enable Win32 long paths» item.
This value is «Not Configured» as default. Enable it.
Then, you don’t have to suffer from the long path issue any longer.
So far, we’ve walked through the node-gyp
issue while working with the node.js app on Windows 11. I hope this approach helps.
node-gyp, short for generate your projects, is a tool that lets us build native add-ons for Node.js. Due to historical reasons, which we’ll outline in this article, using node-gyp can easily result in problems that are hard to resolve.
In this article, we’ve grouped all the major issues with node-gyp into three categories, including dependencies of node-gyp, add-on compilation errors, and binding contract violation. We’ll review each category one-by-one, offering solutions along the way.
If you aren’t already familiar with node-gyp or haven’t run into these issues yourself, I recommend reviewing the project’s README file first. Let’s get started!
node-gyp dependencies
Before we start, it’s important to note that if you have Node.js installed, you probably already have node-gyp installed but not exposed globally. If you only need to compile add-ons during the project setup, Node.js should cover it for you. However, if you are an add-on developer, you probably need to install node-gyp globally.
To use node-gyp, first, we’ll need to install a Python runtime, the make
utility, and a C or C++ compiler. Already, we run into an issue with the first requirement. node-gyp expects Python ≥v3.6, not Python v2.x. If you’re not a Python developer, you might not realize that Python v.3 isn’t backward-compatible with its previous major version.
Additionally, many modern operating systems provide default runtimes from the first boot-up, however, these runtimes may not comply with node-gyp’s requirements. Be sure to properly install the correct dependencies for your system before starting with node-gyp.
Lastly, many software developers tend to miss the CPU architecture, frequently assuming that the 64-bit version of the x86 instruction set will work. But as new CPUs constantly appear on the market, this could not be further from the truth.
Add-on compilation errors
Usually, developers write add-ons for Node.js in C with N-API bindings or C++ with NAN bindings. We’ll cover bindings in depth later on, but for now, keep in mind that there are at least two ways to bridge the add-on code to the Node.js runtime.
Usually, when you install an external dependency that uses node-gyp, node-gyp will download pre-built binaries that match your architecture and the Node.js version on your system. node-gyp will compile the add-on code only when it doesn’t find a match, which can cause problems.
Most programming languages are backward-compatible, or at least have a minor release version that is. Imagine that the author of an add-on wrote the code but used a higher version of a language than the one supported on your system. You simply would not be able to compile the add-on.
To solve compilation errors, you can either fork its codebase or upgrade or downgrade your compiler toolchain.
Binding contract violation
Previously, we mentioned two types of bindings, NAN, Native Abstraction for Node.js, and Node-API, formerly known as N-API. The third type of bindings include V8, libuv, and Node.js header files.
V8 is a JavaScript and WebAssembly engine used by Node.js. Libuv is a C library used by Node.js to get support for asynchronous I/O.
The first binding method, NAN, provides header files that enable add-ons to interact directly with the V8 runtime. It is similar to using plain V8 header files, just with extra precaution. Since every Node.js release might use a different V8 version, add-ons that use NAN indirectly depend on the V8 version utilized by their users.
If an add-on code expects more or different functionality from V8 than what it provides, the add-on can fail during the linking phase. Or worse, linking may succeed, only for the add-on to crash during runtime due to the presence of incorrect header files.
To remedy these pitfalls, Node.js now exposes Node-API, a stable API independent from the JavaScript runtime. However, this method is not perfect either. The target Node version needs to implement Node-API in the version used by the add-on. To know which version of Node-API you can use against a particular Node.js installation, you should check the version matrix.
Sadly, there is no simple solution for binding contract violations. If you’re the code’s author, you could adjust it, otherwise, you may need to upgrade or downgrade your Node.js version. Later in the article, we’ll cover a few more generic ways to deal with similar issues.
Issue categorization
You may have already realized that the problems reported as node-gyp issues are, in fact, issues with the toolchain used for building add-on code. Now, let’s cover how to categorize the issue to apply the correct solution. When you run into a problem, you can ask yourself the following question:
- Who is the issue reporter? Is it an add-on publisher or an add-on consumer?
- What is the architecture and the toolchain of your machine?
- What are the target Node.js versions?
- Does the add-on use NAN or Node-API?
- Which programming language does the add-on use?
Simply put, the add-on publisher has more tools at their disposal when fixing potential problems than a consumer. The architecture and the toolchain influence the whole build process. The target Node.js versions might impair the way NAN cooperates, and some low versions do not support Node-API. The programming language of the add-on influences the contact point between Node and the NAN/Node-API bindings.
It’s worth noting that one installation of an add-on that uses node-gyp for building could trigger many issues, each in different categories.
Checking the architecture and toolchain requires knowledge about the software and hardware of your machine. You should acquire information about your operating system and the CPU/GPU. You likely work on an x86-64-compatible instruction set, but it’s better to verify this information.
To check the version of Python 3 currently used on your terminal, run the following command:
python3 --version
In your terminal, run the command below to check what version of the C/C++ compiler toolchain you’re using:
gcc --version
To check the Node.js version on your machine, use the following code:
node --version
You can dynamically change the executed Node.js version with a Node.js version manager, like either n, available on Linux and macOS, or nvm. However, to avoid using each tool in an automated way, which could cause some of the issues we’ve previously listed, we’ll check the add-on bindings.
Checking the add-on bindings
We need to have access to the codebase of the said add-on. The most important file we need to look into is the binding.gyp
file, usually located in the root directory of the add-on. We should search for all require
statements in it; require("nan")
indicates that the add-on uses NAN, and require("node-addon-api")
indicates that the add-on uses Node-API.
For further clarification, you can see examples on GitHub of binding.gyp
files in NAN and Node-API.
We can also search the entire project for either NAN or Node-API macros, #include <nan.h>
and #include <node_api.h>
. Some projects may also use V8 header files, which use #include <v8.h>
macros.
More great articles from LogRocket:
- Don’t miss a moment with The Replay, a curated newsletter from LogRocket
- Learn how LogRocket’s Galileo cuts through the noise to proactively resolve issues in your app
- Use React’s useEffect to optimize your application’s performance
- Switch between multiple versions of Node
- Discover how to animate your React app with AnimXYZ
- Explore Tauri, a new framework for building binaries
- Compare NestJS vs. Express.js
Checking the programming language
You should see the programming language by the filename extensions. C uses .h
for header files and .c
for source files. On the other hand, C++ uses .h
, .hpp
, and .hxx
for header files and .cpp
and .cxx
for source files.
Add-ons that use the node-addon-api
module are C++ projects. Otherwise, it would be pointless to get declarations of C++ wrapper classes with no intention of using them.
Generic troubleshooting strategies
At this point, if you’ve implemented the above solutions and still haven’t solved the problem you’re facing, we’ve prepared a few generic ideas to try out.
Setting up the Node.js environment and node-gyp dependencies might not be straightforward on your operating system. As an alternative, let’s try building the add-on in a Docker image instead of your local machine, allowing you to control all the dependencies, including the operating system. If you can build the Docker image but still have trouble with your local setup, you’ll know where the problem lies.
As an example, we’ve prepared the following Dockerfile snippet, which builds the SQLite3 add-on on an Alpine Linux instance:
FROM alpine:3.14.2 RUN apk update RUN apk add --no-cache build-base curl git linux-headers nodejs npm py3-pip python3 python3-dev sqlite RUN pip3 install --upgrade pip WORKDIR /opt/showcase RUN npm init -y RUN apk add sqlite RUN npm install sqlite3 --verbose --build-from-source
You can save it as Dockerfile
in the directory of your choice and run with docker build .
We used Alpine Linux because of its lightweight nature. You may have noticed that we had to add our dependencies by hand. As an exercise, you can remove some dependencies and see how each influences the installation of SQLite3. Additionally, you might check the proposed Dockerfile for node-rdkafka, although it is somewhat dated.
You might also try changing the architecture within the Docker image, for instance, you can choose a 32-bit version of Ubuntu. We trust you can use this hint for old projects, but please note that it is rather unlikely for you to run a 64-bit virtualized operating system on a 32-bit host.
Upgrading or downgrading a Node.js version is trivial with Docker. To speed up the process, the Node.js Docker Team provides Docker images for different versions.
If you have access to the codebase of a NAN-based add-on, you might try to switch to Node-API. It requires you to have prior experience with writing add-ons. You should as well have enough resources to undertake such a task.
Conclusion and resources
Hopefully, by the end of this tutorial, you’ve been able to resolve your issue with node-gyp. We learned how to categorize issues into three common categories by asking a series of questions, then offered unique solutions tailored to each category. We then provided a more generic, universal solution to node-gyp issues that uses a Dockerfile.
In rare instances where the steps proposed above don’t work for you, you can browse the following resources and support channels. I hope you enjoyed this tutorial and have a stronger understanding of node-gyp.
Resources:
- https://nodejs.org/api/addons.html
- https://nodejs.org/api/n-api.html
- https://github.com/nodejs/node-addon-api
- https://github.com/mapbox/node-pre-gyp
Support:
- StackOverflow
- GitHub Issues of NAN
- GitHub Issues of Node-API
- Node.js Add–on API Working Group
200’s only Monitor failed and slow network requests in production
Deploying a Node-based web app or website is the easy part. Making sure your Node instance continues to serve resources to your app is where things get tougher. If you’re interested in ensuring requests to the backend or third party services are successful, try LogRocket. https://logrocket.com/signup/
LogRocket is like a DVR for web and mobile apps, recording literally everything that happens while a user interacts with your app. Instead of guessing why problems happen, you can aggregate and report on problematic network requests to quickly understand the root cause.
LogRocket instruments your app to record baseline performance timings such as page load time, time to first byte, slow network requests, and also logs Redux, NgRx, and Vuex actions/state. Start monitoring for free.
- Главная
- Front-end
- Установка node-gyp на Windows 8
Для работы некоторых модулей Node.js (например, MongoDB, Sails.js, Deployd) нужна компиляция нативного кода, написанного на C++. Это возможно с помощью модуля node-gyp, который, в свою очередь, собирает V8 используя питоновский gyp. Поэтому настроить node-gyp на Windows не просто, хотя на Ubuntu Linux у меня проблем с этим не возникало. В этом посте я поделюсь своим опытом исправления ошибок, которые возникали у меня при установке node-gyp на Windows, и опишу последовательность действий, которая позволила мне заставить сборку работать.
Для установки node-gyp необходимы Python и C++. Поэтому сначала ставим:
- Python 2.7
- Microsoft Visual Studio C++ 2013 for Windows Desktop Express
- и Windows 7 64-bit SDK, если у вас 64-битная система.
После этого надо запустить установку node-gyp глобально:
Если node-gyp установлен локально для проекта, то в некоторых случаях возможна ошибка Failed at install script ‘node-gyp rebuild’, например:
npm ERR! bufferutil@1.2.1 install: `node—gyp rebuild` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the bufferutil@1.2.1 install script ‘node-gyp rebuild’. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the bufferutil package, npm ERR! not with npm itself. |
Если у вас не установлен Python, или Node.js не может его найти, возникает ошибка Can’t find Python executable “python”, you can set the PYTHON env variable:
> node-gyp rebuild gyp info it worked if it ends with ok gyp info using node-gyp@3.3.0 gyp info using node@5.5.0 | win32 | x64 gyp ERR! configure error gyp ERR! stack Error: Can‘t find Python executable «python», you can set the PYTHON env variable. ... gyp ERR! node -v v5.5.0 gyp ERR! node-gyp -v v3.3.0 gyp ERR! not ok |
Это лечится установкой Python 2.7 (важно ставить именно эту версию, не знаю почему, но версия 3 не поддерживается!), и указанием в терминале пути к исполняемому файлу питона:
set PYTHON=C:UsersIrinaAppDataLocalProgramsPythonPython27python.exe |
Но указывать путь нужно будет каждый раз, когда вы запускаете node-gyp. Поэтому, если вы используете кастомный терминал (а я надеюсь, что вы это делаете), то лучше добавить эту команду в список команд, которые выполняются при запуске терминала.
Если не найден компилятор С++, то вы увидите ошибку `gyp` failed with exit code: 1:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
> node-gyp rebuild gyp info it worked if it ends with ok gyp info using node-gyp@3.3.0 gyp info using node@5.5.0 | win32 | x64 gyp http GET https://nodejs.org/download/release/v5.5.0/node-v5.5.0-headers.tar.gz gyp http 200 https://nodejs.org/download/release/v5.5.0/node-v5.5.0-headers.tar.gz gyp http GET https://nodejs.org/download/release/v5.5.0/SHASUMS256.txt gyp http GET https://nodejs.org/download/release/v5.5.0/win-x64/node.lib gyp http GET https://nodejs.org/download/release/v5.5.0/win-x86/node.lib gyp http 200 https://nodejs.org/download/release/v5.5.0/SHASUMS256.txt gyp http 200 https://nodejs.org/download/release/v5.5.0/win-x86/node.lib gyp http 200 https://nodejs.org/download/release/v5.5.0/win-x64/node.lib gyp info spawn C:UsersIrinaAppDataLocalProgramsPythonPython27python.exe gyp info spawn args [ ‘C:\Users\Irina\AppData\Roaming\npm\node_modules\node-gyp\gyp\gyp_main.py’, ... gyp info spawn args ‘-Goutput_dir=.’ ] gyp: binding.gyp not found (cwd: C:UsersIrinaDocumentsproject) while trying to load binding.gyp gyp ERR! configure error gyp ERR! stack Error: `gyp` failed with exit code: 1 gyp ERR! stack at ChildProcess.onCpExit (C:UsersIrinaAppDataRoamingnpmnode_modulesnode-gyplibconfigure.js:305:16) gyp ERR! stack at emitTwo (events.js:100:13) gyp ERR! stack at ChildProcess.emit (events.js:185:7) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12) gyp ERR! System Windows_NT 6.3.9600 gyp ERR! command «C:\Program Files\nodejs\node.exe» «C:\Users\Irina\AppData\Roaming\npm\node_modules\node-gyp\bin\node-gyp.js» «rebuild» gyp ERR! cwd C:UsersIrinaDocumentsproject gyp ERR! node -v v5.5.0 gyp ERR! node-gyp -v v3.3.0 gyp ERR! not ok |
Чтобы ее исправить, надо поставить Visual Studio C++ 2013 Express, ссылка на нее есть в начале поста. Имейте в виду, что это огромная среда, которая займет 6,5 гигабайт (!) места на диске (в такие моменты я особенно сильно ненавижу винду – компилятор gpp на Ubuntu в установленном виде занимает всего 17Мб). После этого надо перезагрузить компьютер, и запустить node-gyp rebuild.
© 2012-2023 Блог Ирины Соколовской