使用之前先看官网简介:node-gyp - npm
Node.js native addon build tool
node-gyp
is a cross-platform command-line tool written in Node.js for compiling native addon modules for Node.js. It contains a vendored copy of the gyp-next project that was previously used by the Chromium team, extended to support the development of Node.js native addons.Note that
node-gyp
is not used to build Node.js itself.Multiple target versions of Node.js are supported (i.e.
0.8
, ...,4
,5
,6
, etc.), regardless of what version of Node.js is actually installed on your system (node-gyp
downloads the necessary development files or headers for the target version).
gyp是为Chromium项目创建的项目生成工具,可以从平台无关的配置生成平台相关的Visual Studio、Xcode、Makefile的项目文件。这样一来我们就不需要花额外的时间处理每个平台不同的项目配置以及项目之间的依赖关系。
npm install时遇到报错:
Building: D:\mysoft\nvm-nodejs\node.exe D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags=
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli 'D:\\mysoft\\nvm-nodejs\\node.exe',
gyp verb cli 'D:\\WorkSpace\\dev\\xxx\\xxx_node\\xxx-task-center-ext\\node_modules\\node-gyp\\bin\\node-gyp.js',
gyp verb cli 'rebuild',
gyp verb cli '--verbose',
gyp verb cli '--libsass_ext=',
gyp verb cli '--libsass_cflags=',
gyp verb cli '--libsass_ldflags=',
gyp verb cli '--libsass_library='
gyp verb cli ]
gyp info using node-gyp@3.8.0
gyp info using node@12.22.3 | win32 | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2
gyp verb `which` failed at getNotFoundError (D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\which\which.js:13:12)
gyp verb `which` failed at F (D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\which\which.js:68:19)
gyp verb `which` failed at E (D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\which\which.js:80:29)
gyp verb `which` failed at D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\which\which.js:89:16
gyp verb `which` failed at D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\isexe\index.js:42:5
gyp verb `which` failed at D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\isexe\windows.js:36:5
gyp verb `which` failed at FSReqCallback.oncomplete (fs.js:168:21)
gyp verb `which` failed python2 Error: not found: python2
gyp verb `which` failed at getNotFoundError (D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\which\which.js:13:12)
gyp verb `which` failed at F (D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\which\which.js:68:19)
gyp verb `which` failed at E (D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\which\which.js:80:29)
gyp verb `which` failed at D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\which\which.js:89:16
gyp verb `which` failed at D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\isexe\index.js:42:5
gyp verb `which` failed at D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\isexe\windows.js:36:5
gyp verb `which` failed at FSReqCallback.oncomplete (fs.js:168:21) {
gyp verb `which` failed code: 'ENOENT'
gyp verb `which` failed }
gyp verb check python checking for Python executable "python" in the PATH
gyp verb `which` succeeded python C:\mysoft\Python\Python39\python.EXE
gyp ERR! configure error
gyp ERR! stack Error: Command failed: C:\mysoft\Python\Python39\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack File "", line 1
gyp ERR! stack import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack
gyp ERR! stack at ChildProcess.exithandler (child_process.js:308:12)
gyp ERR! stack at ChildProcess.emit (events.js:314:20)
gyp ERR! stack at maybeClose (internal/child_process.js:1022:16)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
gyp ERR! System Windows_NT 10.0.19042
gyp ERR! command "D:\\mysoft\\nvm-nodejs\\node.exe" "D:\\WorkSpace\\dev\\xxx\\xxx_node\\xxx-task-center-ext\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsalibsass_library="
gyp ERR! cwd D:\WorkSpace\dev\xxx\xxx_node\xxx-task-center-ext\node_modules\node-sass
gyp ERR! node -v v12.22.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
这个错误应该是npm版本的问题,我当前的nodejs版本是12.22.3,npm版本是6.14.13(网上说npm6.14.13版本之后就可以解决,这么有针对性嘛[face]emoji:010.png[/face])
然后我直接使用nvm安装16最新版16.15.0,npm版本8.5.5,问题解决!!!
另外:
如果好奇如何实现找本地环境变量的,可参考以下:
test-find-node-directory.js
test-find-python.js
node-gyp包使用-Node.js文档类资源-CSDN下载
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)