Jest无法在依赖项中找到包画布,即使它存在。yarn run test
失败,并出现以下错误。
packages/first/src/layouts/EventsTable.spec.tsx
● Test suite failed to run
Cannot find module '../build/Release/canvas.node'
Require stack:
- /Users/abc/Documents/monorepo/node_modules/canvas/lib/bindings.js
- /Users/abc/Documents/monorepo/node_modules/canvas/lib/canvas.js
- /Users/abc/Documents/monorepo/node_modules/canvas/index.js
- /Users/abc/Documents/monorepo/node_modules/jsdom/lib/jsdom/utils.js
- /Users/abc/Documents/monorepo/node_modules/jsdom/lib/jsdom/living/events/MouseEvent-impl.js
- /Users/abc/Documents/monorepo/node_modules/jsdom/lib/jsdom/living/generated/MouseEvent.js
- /Users/abc/Documents/monorepo/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js
- /Users/abc/Documents/monorepo/node_modules/jsdom/lib/jsdom/living/aborting/AbortSignal-impl.js
- /Users/abc/Documents/monorepo/node_modules/jsdom/lib/jsdom/living/generated/AbortSignal.js
- /Users/abc/Documents/monorepo/node_modules/jsdom/lib/jsdom/living/generated/AddEventListenerOptions.js
......
字符串
Canvas已安装并显示在依赖项列表中。
yarn why canvas
└─ pdfjs-dist@npm:3.11.174
└─ canvas@npm:2.11.2 (via npm:^2.11.2)
型
已尝试删除所有软件包rm -rf node_modules
并重新安装,但问题仍然存在。
节点版本- v18.16.1
Yarn版本- v3.2.3
1条答案
按热度按时间m4pnthwp1#
尝试检查
canvas
是否实际安装并存在于node_modules中。(对我来说,它没有安装,pdfjs-dist
和react-pdf
都没有抱怨。)运行
npm ci
对我来说工作得很好,但是使用npm ci --ignore-scripts
会导致(无声的)问题,因为需要脚本才能使其工作。在
npm ci --ignore-scripts
之后可以使用npm rebuild canvas
来解决这个问题。顺便说一句:当试图手动安装它时,
npm install canvas
个我得到了一个错误,并已应用手动命令描述这里第一:https://github.com/Automattic/node-canvas?tab=readme-ov-file#installation
然后安装canvas工作并通过测试。
如果你在Jenkins上遇到类似的问题(使用Docker和Alpine Image),你可以查看这个页面(这对我有帮助):
https://github.com/node-gfx/node-canvas-prebuilt/issues/77#issuecomment-884365161