使用NPM安装JEST时,命令行引发错误

使用NPM安装JEST时,命令行引发错误,npm,jestjs,ts-jest,vite,Npm,Jestjs,Ts Jest,Vite,我只是用Vite初始化了一个Vue3+TypeScript项目,然后我没有做任何其他事情。我没有写一行代码,也没有修改任何文件 我只是直接使用这个命令npmijest-D来安装jest 但是命令行抛出如下错误: $ npm i jest -D npm WARN deprecated har-validator@5.1.5: this library is no longer supported n

我只是用Vite初始化了一个Vue3+TypeScript项目,然后我没有做任何其他事情。我没有写一行代码,也没有修改任何文件

我只是直接使用这个命令
npmijest-D
来安装jest

但是命令行抛出如下错误:

$ npm i jest -D    

                                            
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated node-pre-gyp@0.15.0: Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbox scoped package will recieve updates in the future
npm ERR! code 1
npm ERR! path /Users/apple/Desktop/project/vue3-jest/node_modules/canvas
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@7.1.2
npm ERR! gyp info using node@12.16.1 | darwin | x64
npm ERR! gyp info find Python using Python version 3.9.0 found at "/usr/local/bin/python3"
npm ERR! gyp info spawn /usr/local/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/apple/Desktop/project/vue3-jest/node_modules/canvas/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/apple/Library/Caches/node-gyp/12.16.1/include/node/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=/Users/apple/Library/Caches/node-gyp/12.16.1',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/Users/apple/Library/Caches/node-gyp/12.16.1/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/Users/apple/Desktop/project/vue3-jest/node_modules/canvas',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! /bin/sh: pkg-config: command not found
npm ERR! gyp: Call to 'pkg-config pixman-1 --libs' returned exit status 127 while in binding.gyp. while trying to load binding.gyp
npm ERR! gyp ERR! configure error 
npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
npm ERR! gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
npm ERR! gyp ERR! stack     at ChildProcess.emit (events.js:311:20)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
npm ERR! gyp ERR! System Darwin 18.7.0
npm ERR! gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /Users/apple/Desktop/project/vue3-jest/node_modules/canvas
npm ERR! gyp ERR! node -v v12.16.1
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/apple/.npm/_logs/2021-04-26T15_35_01_442Z-debug.log
$npm我开玩笑-D
npm警告不推荐的har-validator@5.1.5:不再支持此库
npm警告不推荐使用的节点预-gyp@0.15.0:请升级到@mapbox/node pre-gyp:非作用域的node pre-gyp包已弃用,将来只有@mapbox作用域的包将接收更新
npm错误!代码1
npm错误!path/Users/apple/Desktop/project/vue3 jest/node_modules/canvas
npm错误!命令失败
npm错误!命令sh-c节点gyp rebuild
npm错误!gyp信息如果以ok结尾,它就起作用了
npm错误!gyp信息使用节点-gyp@7.1.2
npm错误!gyp信息使用node@12.16.1|达尔文| x64
npm错误!gyp info在“/usr/local/bin/python3”找到使用Python版本3.9.0的Python
npm错误!gyp信息产卵/usr/local/bin/python3
npm错误!gyp信息产卵参数[
npm ERR!gyp info spawn args'/usr/local/lib/node_modules/npm/node_modules/node gyp/gyp/gyp_main.py',
npm ERR!gyp信息生成参数“binding.gyp”,
npm ERR!gyp信息生成参数'-f',
npm错误!gyp信息生成参数'make',
npm ERR!gyp信息产卵参数'-I',
npm ERR!gyp info spawn args'/Users/apple/Desktop/project/vue3 jest/node_modules/canvas/build/config.gypi',
npm ERR!gyp信息产卵参数'-I',
npm ERR!gyp info spawn args'/usr/local/lib/node_modules/npm/node_modules/node gyp/addon.gypi',
npm ERR!gyp信息产卵参数'-I',
npm ERR!gyp info spawn args'/Users/apple/Library/Caches/node gyp/12.16.1/include/node/common.gypi',
npm ERR!gyp info spawn args'-dllibrary=shared_library',
npm ERR!gyp信息生成参数'-Dvisibility=default',
npm ERR!gyp info spawn args'-Dnode_root_dir=/Users/apple/Library/Caches/node gyp/12.16.1',
npm ERR!gyp info spawn args'-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node gyp',

npm ERR!gyp info spawn args'-Dnode_lib_file=/Users/apple/Library/Caches/node gyp/12.16.1/我不知道npm安装失败的原因,但工作正常:

yarn add jest --dev
我为自己工作