Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Missing dependency on preact / react (ghost dependency)

未關閉
#262 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
35/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
javascript, react

研究方向

檢查 package.json 中的相依性宣告,以及報告中描述的 preact 和 react 匯入路徑。使用 Yarn Plug'n'Play 重現失敗情況,然後比較 issue 中的相依性選項。當 package 正確宣告其執行階段需求,且兩個受支援的函式庫都不會發生 ghost-dependency 錯誤時,即表示完成。

由索引模型根據 Issue 內容生成。

描述

This module tries to import / require from preact, but does not declare it as a dependency in its package.json (a ghost dependency). This is an error, yarn requires all dependency to be listed properly:

Module not found: Error: Can't resolve 'preact' in 'C:\Users\user\AppData\Local\Yarn\Berry\cache\htm-npm-3.1.1-e3b831f850-10.zip\node_modules\htm\preact'
resolve 'preact' in 'C:\Users\user\AppData\Local\Yarn\Berry\cache\htm-npm-3.1.1-e3b831f850-10.zip\node_modules\htm\preact'
  Parsed request is a module
  using description file: C:\Users\user\AppData\Local\Yarn\Berry\cache\htm-npm-3.1.1-e3b831f850-10.zip\node_modules\htm\preact\package.json (relative path: .)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      request is not managed by the pnpapi
        htm tried to access preact, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.
        Required package: preact
        Required by: htm@npm:3.1.1 (via C:\Users\user\AppData\Local\Yarn\Berry\cache\htm-npm-3.1.1-e3b831f850-10.zip\node_modules\htm\preact\)
 @ ../../../../../../AppData/Local/Yarn/Berry/cache/@bpmn-io-diagram-js-ui-npm-0.2.3-01795dd8e0-10.zip/node_modules/@bpmn-io/diagram-js-ui/lib/index.js 1:0-34 1:0-34
 @ ../../../../../../AppData/Local/Yarn/Berry/cache/diagram-js-npm-15.2.4-de7db86f90-10.zip/node_modules/diagram-js/lib/ui/index.js 1:0-39 1:0-39
 @ ../../../../../../AppData/Local/Yarn/Berry/cache/diagram-js-npm-15.2.4-de7db86f90-10.zip/node_modules/diagram-js/lib/features/popup-menu/PopupMenu.js 1:0-4:18 132:2-8 133:4-8 278:2-8  
 @ ../../../../../../AppData/Local/Yarn/Berry/cache/diagram-js-npm-15.2.4-de7db86f90-10.zip/node_modules/diagram-js/lib/features/popup-menu/index.js 1:0-36 12:23-32
 @ ../../../../../../AppData/Local/Yarn/Berry/cache/bpmn-js-npm-18.2.0-5474b88486-10.zip/node_modules/bpmn-js/lib/features/align-elements/index.js 3:0-65 13:4-19
 @ ../../../../../../AppData/Local/Yarn/Berry/cache/bpmn-js-npm-18.2.0-5474b88486-10.zip/node_modules/bpmn-js/lib/Modeler.js 12:0-60 167:2-21
 @ ./src/bpmn-editor/render-bpmn-editor.ts 7:0-48 33:31-41
 @ ./src/bpmn-editor/index.ts 1:0-40 1:0-40

The same goes for react. Possible ways how the dependencies could be fixed:

  • declare both react and preact as dependencies (will always install both preact and react)
  • declare both react and preact as optional peer dependencies (preferred) (will force users to install both react and preact)
  • create 2 separate NPM packages, so that each package can declare its dependencies properly

Workaround

For people affected: You can add the following bandage aid to fix the declared dependencies (file .yarnrc.yml):

packageExtensions:
  htm@*:
    peerDependencies:
      preact: "*"
      react: "*"
    peerDependenciesMeta:
    preact:
      optional: true
    react:
      optional: true
主要語言
JavaScript
星號
9k
分支
181
PR 合併指標
30 天內沒有已合併 PR

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

developit/htm 的其他 Issue

查看 developit/htm 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。