由于node-gyp的原因,npm安装失败

11
我正在尝试使用npm安装filepreview模块,但总是出现错误。这是错误提示:
D:\Program Files\nodejs\PalettenzettelGenerator>npm install filepreview

> fibers@1.0.15 install D:\Program Files\nodejs\PalettenzettelGenerator\node_modules\synchronize\node_modules\fibers
> node build.js || nodejs build.js


D:\Program Files\nodejs\PalettenzettelGenerator\node_modules\synchronize\node_modules\fibers>if not defined npm_config_node_gyp (node "D:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild --release )  else (node "D:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild --release )
gyp ERR! UNCAUGHT EXCEPTION
gyp ERR! stack Error: spawn D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\15.0\Bin\MSBuild.exe ENOENT
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
gyp ERR! stack     at onErrorNT (internal/child_process.js:415:16)
gyp ERR! stack     at process._tickCallback (internal/process/next_tick.js:63:19)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "D:\\Program Files\\nodejs\\node.exe" "D:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--release"
gyp ERR! cwd D:\Program Files\nodejs\PalettenzettelGenerator\node_modules\synchronize\node_modules\fibers
gyp ERR! node -v v10.16.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! This is a bug in `node-gyp`.
gyp ERR! Try to update node-gyp and file an Issue if it does not help:
gyp ERR!     <https://github.com/nodejs/node-gyp/issues>
node-gyp exited with code: 7
Please make sure you are using a supported platform and node version. If you
would like to compile fibers on this machine please make sure you have setup your
build environment--
Windows + OS X instructions here: https://github.com/nodejs/node-gyp
Ubuntu users please run: `sudo apt-get install g++ build-essential`
Alpine users please run: `sudo apk add python make g++`
'nodejs' is not recognized as an internal or external command,
operable program or batch file.
npm WARN PalettenzettelGenerator@1.0.0 No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! fibers@1.0.15 install: `node build.js || nodejs build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the fibers@1.0.15 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\ibrahim\AppData\Roaming\npm-cache\_logs\2019-09-02T08_17_55_828Z-debug.log

我已经搜索了相关内容,通常是关于node-gyp的。我的Node版本是v10.16.0。我也安装了Python 2.7。我的VS版本是2019。
如果只是关于node-gyp模块的话,是否还有其他解决方法可以在Node.js中预览png文件呢?
编辑:
我已卸载了VS2019并安装了VS2017 Build Tools。但仍然出现另一个错误:
D:\Program Files\nodejs\PalettenzettelGenerator>npm install filepreview

> fibers@1.0.15 install D:\Program Files\nodejs\PalettenzettelGenerator\node_modules\synchronize\node_modules\fibers
> node build.js || nodejs build.js


D:\Program Files\nodejs\PalettenzettelGenerator\node_modules\synchronize\node_modules\fibers>if not defined npm_config_node_gyp (node "D:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild --release )  else (node "D:\Program Files\nodejs\node_modules\node-gyp\bin\node-gyp.js" rebuild --release )
Bu çözümde projeler tek tek derlenir. Paralel bir derlemeyi etkinleştirmek için lütfen "/m" anahtarını ekleyin.
  fibers.cc
  coroutine.cc
  win_delay_load_hook.cc
d:\program files\nodejs\palettenzettelgenerator\node_modules\synchronize\node_modules\fibers\src\fibers.cc(122): error C2660: 'v8::String::NewFromOneByte': işlev 2 bağımsız değişken almıyor [D:\Program Files\nodejs\PalettenzettelGenerator\node_modules\synchronize\node_modules\
fibers\build\fibers.vcxproj]
  c:\users\ibrahim\appdata\local\node-gyp\cache\10.16.0\include\node\v8.h(2802): note: 'v8::String::NewFromOneByte' bildirimine bakın (kaynak dosyası derleniyor ..\src\fibers.cc)
d:\program files\nodejs\palettenzettelgenerator\node_modules\synchronize\node_modules\fibers\src\fibers.cc(126): error C2660: 'v8::String::NewFromOneByte': işlev 2 bağımsız değişken almıyor [D:\Program Files\nodejs\PalettenzettelGenerator\node_modules\synchronize\node_modules\
fibers\build\fibers.vcxproj]
  c:\users\ibrahim\appdata\local\node-gyp\cache\10.16.0\include\node\v8.h(2802): note: 'v8::String::NewFromOneByte' bildirimine bakın (kaynak dosyası derleniyor ..\src\fibers.cc)
d:\program files\nodejs\palettenzettelgenerator\node_modules\synchronize\node_modules\fibers\src\fibers.cc(406): warning C4996: 'v8::String::Utf8Value::Utf8Value': kullanım dışı olarak bildirildi [D:\Program Files\nodejs\PalettenzettelGenerator\node_modules\synchronize\node_mo
dules\fibers\build\fibers.vcxproj]
  c:\users\ibrahim\appdata\local\node-gyp\cache\10.16.0\include\node\v8.h(2891): note: 'v8::String::Utf8Value::Utf8Value' bildirimine bakın
d:\program files\nodejs\palettenzettelgenerator\node_modules\synchronize\node_modules\fibers\src\fibers.cc(433): error C2661: 'v8::Function::NewInstance': hiçbir aşırı yüklenmiş işlev 2 bağımsız değişken almaz [D:\Program Files\nodejs\PalettenzettelGenerator\node_modules\synch
ronize\node_modules\fibers\build\fibers.vcxproj]
d:\program files\nodejs\palettenzettelgenerator\node_modules\synchronize\node_modules\fibers\src\fibers.cc(433): error C2672: 'uni::Return': eşleşen aşırı yüklenmiş işlev bulunamadı [D:\Program Files\nodejs\PalettenzettelGenerator\node_modules\synchronize\node_modules\fibers\b
uild\fibers.vcxproj]
d:\program files\nodejs\palettenzettelgenerator\node_modules\synchronize\node_modules\fibers\src\fibers.cc(621): error C2512: 'v8::TryCatch': kullanılabilir uygun varsayılan oluşturucu yok [D:\Program Files\nodejs\PalettenzettelGenerator\node_modules\synchronize\node_modules\f
ibers\build\fibers.vcxproj]
  c:\users\ibrahim\appdata\local\node-gyp\cache\10.16.0\include\node\v8.h(8529): note: 'v8::TryCatch' bildirimine bakın (kaynak dosyası derleniyor ..\src\fibers.cc)
d:\program files\nodejs\palettenzettelgenerator\node_modules\synchronize\node_modules\fibers\src\fibers.cc(628): warning C4996: 'v8::Script::Compile': kullanım dışı olarak bildirildi [D:\Program Files\nodejs\PalettenzettelGenerator\node_modules\synchronize\node_modules\fibers\
build\fibers.vcxproj]
  c:\users\ibrahim\appdata\local\node-gyp\cache\10.16.0\include\node\v8.h(1255): note: 'v8::Script::Compile' bildirimine bakın
d:\program files\nodejs\palettenzettelgenerator\node_modules\synchronize\node_modules\fibers\src\fibers.cc(643): warning C4996: 'v8::TryCatch::StackTrace': kullanım dışı olarak bildirildi [D:\Program Files\nodejs\PalettenzettelGenerator\node_modules\synchronize\node_modules\fi
bers\build\fibers.vcxproj]
  c:\users\ibrahim\appdata\local\node-gyp\cache\10.16.0\include\node\v8.h(8593): note: 'v8::TryCatch::StackTrace' bildirimine bakın
d:\program files\nodejs\palettenzettelgenerator\node_modules\synchronize\node_modules\fibers\src\fibers.cc(741): error C2661: 'v8::Value::ToNumber': hiçbir aşırı yüklenmiş işlev 0 bağımsız değişken almaz [D:\Program Files\nodejs\PalettenzettelGenerator\node_modules\synchronize
\node_modules\fibers\build\fibers.vcxproj]
d:\program files\nodejs\palettenzettelgenerator\node_modules\synchronize\node_modules\fibers\src\fibers.cc(793): error C2660: 'v8::Object::SetAccessor': işlev 2 bağımsız değişken almıyor [D:\Program Files\nodejs\PalettenzettelGenerator\node_modules\synchronize\node_modules\fib
ers\build\fibers.vcxproj]
  c:\users\ibrahim\appdata\local\node-gyp\cache\10.16.0\include\node\v8.h(3348): note: 'v8::Object::SetAccessor' bildirimine bakın (kaynak dosyası derleniyor ..\src\fibers.cc)
d:\program files\nodejs\palettenzettelgenerator\node_modules\synchronize\node_modules\fibers\src\fibers.cc(794): error C2664: 'v8::Maybe<bool> v8::Object::SetAccessor(v8::Local<v8::Context>,v8::Local<v8::Name>,v8::AccessorNameGetterCallback,v8::AccessorNameSetterCallback,v8::M
aybeLocal<v8::Value>,v8::AccessControl,v8::PropertyAttribute,v8::SideEffectType)' : 2 bağımsız değişkeni 'uni::FunctionType (__cdecl *)(v8::Local<v8::String>,const uni::GetterCallbackInfo &)' değerinden 'v8::Local<v8::Name>' değerine dönüştürülemez [D:\Program Files\nodejs\Pal
ettenzettelGenerator\node_modules\synchronize\node_modules\fibers\build\fibers.vcxproj]
  d:\program files\nodejs\palettenzettelgenerator\node_modules\synchronize\node_modules\fibers\src\fibers.cc(794): note: Kaynak türünü hiçbir oluşturucu alamadı veya oluşturucu aşırı yük çözümü belirsizdi
d:\program files\nodejs\palettenzettelgenerator\node_modules\synchronize\node_modules\fibers\src\fibers.cc(795): error C2660: 'v8::Object::SetAccessor': işlev 2 bağımsız değişken almıyor [D:\Program Files\nodejs\PalettenzettelGenerator\node_modules\synchronize\node_modules\fib
ers\build\fibers.vcxproj]
  c:\users\ibrahim\appdata\local\node-gyp\cache\10.16.0\include\node\v8.h(3348): note: 'v8::Object::SetAccessor' bildirimine bakın (kaynak dosyası derleniyor ..\src\fibers.cc)
d:\program files\nodejs\palettenzettelgenerator\node_modules\synchronize\node_modules\fibers\src\coroutine.cc(138): warning C4552: '!': ifade sonucu kullanılmıyor [D:\Program Files\nodejs\PalettenzettelGenerator\node_modules\synchronize\node_modules\fibers\build\fibers.vcxproj
]
gyp ERR! build error
gyp ERR! stack Error: `D:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (D:\Program Files\nodejs\node_modules\node-gyp\lib\build.js:196:23)
gyp ERR! stack     at ChildProcess.emit (events.js:198:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "D:\\Program Files\\nodejs\\node.exe" "D:\\Program Files\\nodejs\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--release"
gyp ERR! cwd D:\Program Files\nodejs\PalettenzettelGenerator\node_modules\synchronize\node_modules\fibers
gyp ERR! node -v v10.16.0
gyp ERR! node-gyp -v v5.0.3
gyp ERR! not ok
node-gyp exited with code: 1
Please make sure you are using a supported platform and node version. If you
would like to compile fibers on this machine please make sure you have setup your
build environment--
Windows + OS X instructions here: https://github.com/nodejs/node-gyp
Ubuntu users please run: `sudo apt-get install g++ build-essential`
Alpine users please run: `sudo apk add python make g++`
'nodejs' is not recognized as an internal or external command,
operable program or batch file.
npm WARN PalettenzettelGenerator@1.0.0 No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! fibers@1.0.15 install: `node build.js || nodejs build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the fibers@1.0.15 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\ibrahim\AppData\Roaming\npm-cache\_logs\2019-09-02T23_04_29_295Z-debug.log

1
如果你在 node-gyp 的问题跟踪器或谷歌上搜索过,你可能会发现(包括你和我在内)由于某些原因,node-gyp 只能与 Python 2.7 兼容 - 但是看一下你的错误日志。 - Mike 'Pomax' Kamermans
我已经安装了Python 2.7,但它仍然出现node-gyp错误。 - sundowatch
你是否已经设置了npm配置 - Medet Tleukabiluly
当我通过“python -V”查看Python版本时,版本为2.7.16。此外,我已经设置了配置。 - sundowatch
所以,让我们继续阅读日志。gyp ERR!stack 错误:在您的路径/环境变量等建议存在的地方不存在 MSBuild.exe ENOENT 表示 MSBuild.exe 不存在于您的路径/环境/等建议存在的位置。您解决了吗?此外,您是否访问了 https://github.com/nodejs/node-gyp,如日志所述,以查看是否这是已知问题,甚至是已记录的事件,具有已记录的解决方案? - Mike 'Pomax' Kamermans
11个回答

21

我曾经遇到过相同的问题。以下是解决方法。您可能需要多次重启计算机以清除所有错误。

解决方法:

1. Install Install VC++ Build Tools  2017 and while installing select V140 from the side menu

2. Install Python 2.7, and add it to your PATH

3. npm config set python python2.7 --global

4. npm config set python C:\Python27\python.exe --global

5. npm config set msvs_version 2015 --global

6. set VCTargetsPath=C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140


**Note:  If you still face error > most likely the problem is node-sass is not installed** 

在这一步之后,您需要重新启动您的计算机。
7. Install the latest versions of Python

8. As Admin:
$ cd "C:\Program Files\nodejs\node_modules\npm"
$ npm install node-gyp

9. $ npm config set msvs_version 2015 --global

Note: that I have VS 2017, but configuring it as ver 2017 won't work. Not sure why.

    10. As Admin:
$ npm install -g node-sass

And finally, one last check:
$ node-sass -v

希望这可以帮到您。

正如@ragavan-rajan所说,当我进行配置并安装与npm install https://github.com/alexeypetrushin/synchronize.git同步时,filepreview成功安装。谢谢。 - sundowatch
很高兴能够帮助到你。 - Ragavan Rajan
嗨@RagavanRajan,我尝试了这些步骤,但它没有起作用。在这里我有更多的细节:https://dev59.com/wr3pa4cB1Zd3GeqPoO1A - Andres
嗨@Andres,你能确认一下你的机器上第一步是什么吗?看起来你安装了不同版本的VC++。 - Ragavan Rajan
我确信那是问题所在。不过我会等待你的回复。 - Ragavan Rajan

4
我正在运行 Windows 11。我按照被接受的答案中的步骤进行操作,但使用了来自node-gyp GitHub 上的答案中的值。

Can confirm this setup works:

msbuild_path = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\MSBuild\\Current\\Bin\\MSBuild.exe"
msvs_version = "2017"

除了我之外,msbuild_path 是不同的;我的 msbuild_path 值如下:

C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild.exe

因此我的步骤如下:

  1. 安装 VC++ Build 工具(这些作为 node 的 Windows 安装 (MSI) 向导 的一部分安装)
  2. 安装 Python 并将其添加到 PATH 中(这也是作为 node 向导的一部分安装的)
  3. npm config set python python2.7 --global
  4. npm config set python C:\Python27\python.exe --global
  5. npm config set msvs_version 2017 --global
  6. npm config set msbuild_path "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\MSBuild\\Current\\Bin\\MSBuild.exe"

一些其他答案建议安装windows-build-tools,这将处理步骤1和2,但我认为这对我没有帮助(因为Node 本身安装了VS Code和Python),但它可能会帮助其他人(先执行此步骤):

npm install --global windows-build-tools


2
这个答案在我的Windows 10和Node 16.x上运行良好! - Maximilian Fixl

3
这是一个 Node 版本问题。我目前使用的是最新特性版本(当前版本),而较新的 Node 还不支持。 要解决这个问题,你可以切换到LTS 版本,通常会得到完全支持。
如果你正在使用brew,切换很容易:
brew unlink node

然后将node lts版本(目前为node@12)链接如下:

brew install node@12 && brew link --overwrite node@12 --force

那对我解决了问题。


2

2

1

这是一个节点版本问题。在我的情况下,我尝试使用不兼容的Node版本14安装node-sass:4.13.0。我卸载了Node14,清除了npm缓存,并使用Chocolately安装了Node 12.8版本。这解决了我的问题。


0

对于 Visual Studio 2022VCTargetsPath 必须设置为 C:\Program Files\Microsoft Visual Studio\2022\<EDITION>\MSBuild\Microsoft\VC\v170\

<EDITION> 更改为您正在运行的 VS 版本(例如 ProfessionalCommunity)。


0
经过尝试多种解决方案(包括被接受的答案),对我来说,这是一个非常简单的解决方案。
我从我正在工作的项目的package.json中移除了 node-sass 并重新安装。

0

解决方案:“gyp ERR!stack 错误:无法找到 D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\15.0\Bin\MSBuild.exe ENOENT”

  1. npm install --global windows-build-tools

                      OR
    

    npm --vs2017 install --global windows-build-tools (在管理员 PowerShell中输入)

    请等待命令提示符上显示“All done!”的消息,表示安装成功。

  2. 安装 Python 2.7 https://www.python.org/downloads/release/python-275/

  3. npm config set python python2.7 --global

  4. npm config set python C:\Python27\python.exe --global

  5. npm config set msbuild_path "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe"

    注意:请检查您的生成工具 2017 的路径位置

    (Visual Studio Build Tool 2017)

  6. npm install

谢谢,

Viral Kalaria


0

我关闭了Visual Studio自动更新npm包的功能。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接