How to solve npm ERR! code 1 when installing webpack

4.5k Views Asked by At

I have a lots of errors when I want to install webpack. My version of node is: v14.17.0 version of npm: 7.13.0 Im on windows 10

Here are the errors:

npm ERR! code 1
npm ERR! path D:\LocalSites\fundraise-better\app\public\wp-content\themes\fundraisebetter\node_modules\fibers
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node build.js || nodejs build.js
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | win32 | ia32
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Command failed: C:\Python39\python.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: invalid syntax
npm ERR! gyp ERR! stack
npm ERR! gyp ERR! stack     at ChildProcess.exithandler (child_process.js:319:12)
npm ERR! gyp ERR! stack     at ChildProcess.emit (events.js:376:20)
npm ERR! gyp ERR! stack     at maybeClose (internal/child_process.js:1055:16)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
npm ERR! gyp ERR! System Windows_NT 10.0.19041
npm ERR! gyp ERR! command "C:\\Program Files (x86)\\nodejs\\node.exe" "D:\\LocalSites\\fundraise-better\\app\\public\\wp-content\\themes\\fundraisebetter\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--release"
npm ERR! gyp ERR! cwd D:\LocalSites\fundraise-better\app\public\wp-content\themes\fundraisebetter\node_modules\fibers
npm ERR! gyp ERR! node -v v14.17.0
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok
npm ERR! node-gyp exited with code: 1
npm ERR! Please make sure you are using a supported platform and node version. If you
npm ERR! would like to compile fibers on this machine please make sure you have setup your
npm ERR! build environment--
npm ERR! Windows + OS X instructions here: https://github.com/nodejs/node-gyp
npm ERR! Ubuntu users please run: `sudo apt-get install g++ build-essential`
npm ERR! RHEL users please run: `yum install gcc-c++` and `yum groupinstall 'Development Tools'`
npm ERR! Alpine users please run: `sudo apk add python make g++`
npm ERR! 'nodejs' is not recognized as an internal or external command,
npm ERR! operable program or batch file.
npm timing npm Completed in 240044ms
3

There are 3 best solutions below

0
On

The problem is a native module problem! It's a common problem!

A native module is a module that have a binding to a native program and binaries! For example a c++ project! Therefor project build and compilation is needed! For this most packages use node-gyp!

The problem is simple! You have a problem where your environment is missing the necessary build and compilation tools!

If you check the error message well! It's all said!

npm ERR! Please make sure you are using a supported platform and node version. If you
npm ERR! would like to compile fibers on this machine please make sure you have setup your build environment--
npm ERR! Windows + OS X instructions here: https://github.com/nodejs/node-gyp
npm ERR! Ubuntu users please run: sudo apt-get install g++ build-essential
npm ERR! RHEL users please run: yum install gcc-c++ and yum groupinstall 'Development Tools'
npm ERR! Alpine users please run: sudo apk add python make g++

So depending on what platform you are! Linux, macos or windows! Follow the instruction above!

You can simply go and check https://github.com/nodejs/node-gyp to see the different instruction!

Python is required in all platforms! (Node-gyp use python heavily that's why)

enter image description here

In linux gcc is used! (check the message error above! For instruction)

"
debian based: sudo apt-get install g++ build-essential,
Redhat and fedora: yum install gcc-c++ and yum groupinstall 'Development Tools'
Any other destribution search for the equivalent! I never fell in such problem in linux! As most distribution have it all!
"

In windows visual studio build tools are needed

https://github.com/nodejs/node-gyp#on-windows

In macos clang is used! And xcode need to have clang!

https://github.com/nodejs/node-gyp#on-macos

Check the node-gyp doc!

Steps from doc

On macOS

ATTENTION: If your Mac has been upgraded to macOS Catalina (10.15), please read macOS_Catalina.md.

  • Python v3.6, v3.7, v3.8, or v3.9
  • Xcode
    You also need to install the XCode Command Line Tools by running xcode-select --install. Alternatively, if you already have the full Xcode installed, you can find them under the menu Xcode -> Open Developer Tool -> More Developer Tools.... This step will install clang, clang++, and make.

On Windows

Install the current version of Python from the Microsoft Store package.

Install tools and configuration manually:

Install Visual C++ Build Environment: Visual Studio Build Tools (using "Visual C++ build tools" workload) or Visual Studio Community (using the "Desktop development with C++" workload) Launch cmd,

npm config set msvs_version 2017

Big important!

If the above steps didn't work for you, please visit Microsoft's Node.js Guidelines for Windows for additional tips.

To target native ARM64 Node.js on Windows 10 on ARM, add the components "Visual C++ compilers and libraries for ARM64" and "Visual C++ ATL for ARM64".

Once downloading the build tools installer from the link above! Or from the download page here

enter image description here

The tool go like this

enter image description here

You can check vscode doc too for c++: https://code.visualstudio.com/docs/cpp/config-msvc

All is needed is to install c++ build tools! And the right elements!

You can check Installing MS C++ 14.0 for python without Visual Studio too for extra sense!

And the easy tool

On windows this article both give good explanation and an easy way for the setup

https://spin.atomicobject.com/2018/06/18/windows-node-js/

Compiling Extensions We don’t have any of our own extensions that need building in our project, but some of our dependencies (namely, node-sass) do.

Extensions like these are built with node-gyp, and node-gyp needs two things: Python (2… wince) and a C compiler, neither of which are standard equipment on a Windows system. If you don’t have them and you need them to build extensions, you will see a long string of gyp ERR! messages when you install dependencies.

Thankfully, there’s a reasonably easy way to install them already configured for node-gyp: windows-build-tools.

After you’ve installed the Scoop nodejs package above, and assuming you installed Sudo, you can now run:

sudo npm install --global --production windows-build-tools

(if you haven't gone with the scoop package command way! Then just remove sudo and run it on a console that have Admin rights!

Note that we have observed these installers rebooting a system at least once, which effectively aborted the process. We fixed this in this one case by re-running the installer like so:

sudo npm uninstall --global windows-build-tools
sudo npm install --global --production windows-build-tools

From windows-build-tools package doc!

On Windows? Want to compile native Node modules? Install the build tools with this one-liner. Start PowerShell as Administrator and run:

npm install --global windows-build-tools

enter image description here

After installation, npm will automatically execute this module, which downloads and installs Visual C++ Build Tools, provided free of charge for most users by Microsoft (as part of Visual Studio Community, please consult the license to determine whether or not you're eligible). These tools are required to compile popular native modules. If not already installed, it will also install Python 3.8, configuring your machine and npm appropriately.

||| [Windows Vista / 7 only] requires .NET Framework 4.5.1 (Currently not installed automatically by this package)

Both installations are conflict-free, meaning that they do not mess with existing installations of Visual Studio, C++ Build Tools, or Python. If you see anything that indicates otherwise, please file a bug.

VS 2017 or 2015

This module is capable of installing either the build tools from Visual Studio 2017 or Visual Studio 2015.

By default, this tool will install the 2017 build tools. To change that, run this script with the --vs2015 parameter.

VS 2019

As by node-gyp doc! And guide! They are suggesting vs 2017

Launch cmd, npm config set msvs_version 2017

Most packages use vs 2015 or 2017! 2017 Should do well! If you get any problems for some reason! Install them both!

Also if VS 2019 is needed at any time and any reason! One can go with the manual way stated above!

and use npm config set msvs_version 2019

One can always use that for version change! When it comes to npm!

Well it's a thing that you may never need to care about! But just in case!

packages with native modules that may have complications! Generally they will state how to go about the build tools! If there is any!

0
On

try in admin mode

npm install --global windows-build-tools
0
On

I finaly solved the issue. The node-gyp was installed on my machine but still not working. Finally running this command fixed the issue: Set-ExecutionPolicy RemoteSigned -Scope CurrentUser