[Bug]: builder-webpack5 在 8.2.0 之后无法解析 'storybook/internal/docs-tools'

hwazgwia  于 4个月前  发布在  Webpack
关注(0)|答案(8)|浏览(70)

描述错误

尝试从 8.1.11 升级到 8.2.0 (或 8.2.2) 时,出现以下错误。似乎在依赖项精简(顺便说一下,这真的很棒)之后,可能需要添加回某个依赖项。

SB_BUILDER-WEBPACK5_0002 (WebpackInvocationError): Module not found: Error: Can't resolve 'storybook/internal/docs-tools' in './node_modules/.aspect_rules_js/@storybook+react@8.2.2_-2113478954/node_modules/@storybook/react/dist'
    at ./node_modules/.aspect_rules_js/@storybook+builder-webpack5@8.2.2_303820626/node_modules/@storybook/builder-webpack5/dist/index.js:1:8835
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/HookWebpackError.js:68:3
    at Hook.eval [as callAsync] (eval at create (./node_modules/.aspect_rules_js/tapable@2.2.1/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (./node_modules/.aspect_rules_js/tapable@2.2.1/node_modules/tapable/lib/Hook.js:18:14)
    at Cache.shutdown (./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/Cache.js:156:23)
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/Compiler.js:1378:15
    at Hook.eval [as callAsync] (eval at create (./node_modules/.aspect_rules_js/tapable@2.2.1/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (./node_modules/.aspect_rules_js/tapable@2.2.1/node_modules/tapable/lib/Hook.js:18:14)
    at Compiler.close (./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/Compiler.js:1371:23)
    at ./node_modules/.aspect_rules_js/@storybook+builder-webpack5@8.2.2_303820626/node_modules/@storybook/builder-webpack5/dist/index.js:1:8820
    at finalCallback (./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/Compiler.js:496:32)
    at onCompiled (./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/Compiler.js:510:20)
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/Compiler.js:1326:21
    at eval (eval at create (./node_modules/.aspect_rules_js/tapable@2.2.1/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:16:1)
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/EntryPlugin.js:49:5
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/Compilation.js:2279:13
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/Compilation.js:2168:6
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/Compilation.js:2030:13
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/util/AsyncQueue.js:354:5
    at Hook.eval [as callAsync] (eval at create (./node_modules/.aspect_rules_js/tapable@2.2.1/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncQueue._handleResult (./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/util/AsyncQueue.js:324:21)
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/util/AsyncQueue.js:307:11
    at onTransitiveTasksFinished (./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/Compilation.js:1544:20)
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/Compilation.js:1530:7
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/Compilation.js:2030:13
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/util/AsyncQueue.js:354:5
    at Hook.eval [as callAsync] (eval at create (./node_modules/.aspect_rules_js/tapable@2.2.1/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncQueue._handleResult (./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/util/AsyncQueue.js:324:21)
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/util/AsyncQueue.js:307:11
    at onTransitiveTasksFinished (./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/Compilation.js:1544:20)
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/Compilation.js:1530:7
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/Compilation.js:1860:14
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/util/AsyncQueue.js:354:5
    at Hook.eval [as callAsync] (eval at create (./node_modules/.aspect_rules_js/tapable@2.2.1/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncQueue._handleResult (./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/util/AsyncQueue.js:324:21)
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/util/AsyncQueue.js:307:11
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/Compilation.js:2105:13
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/NormalModuleFactory.js:904:13
    at eval (eval at create (./node_modules/.aspect_rules_js/tapable@2.2.1/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:10:1)
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/NormalModuleFactory.js:341:22
    at eval (eval at create (./node_modules/.aspect_rules_js/tapable@2.2.1/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:1)
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/NormalModuleFactory.js:518:22
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/NormalModuleFactory.js:151:11
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/NormalModuleFactory.js:776:25
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/NormalModuleFactory.js:988:8
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/NormalModuleFactory.js:1118:5
    at ./node_modules/.aspect_rules_js/neo-async@2.6.2/node_modules/neo-async/async.js:6883:13
    at ./node_modules/.aspect_rules_js/webpack@5.93.0_275684263/node_modules/webpack/lib/NormalModuleFactory.js:1101:45
    at finishWithoutResolve (./node_modules/.aspect_rules_js/enhanced-resolve@5.17.0/node_modules/enhanced-resolve/lib/Resolver.js:567:11)
    at ./node_modules/.aspect_rules_js/enhanced-resolve@5.17.0/node_modules/enhanced-resolve/lib/Resolver.js:656:15

复现链接

.

复现步骤

  • 无响应*

系统

.

附加上下文

  • 无响应*
qco9c6ql

qco9c6ql1#

请提供一个复制品,我可以看一下。
我怀疑你的依赖项中存在版本冲突,导致storybook包的版本比它应该的版本旧。

q9rjltbz

q9rjltbz2#

@tony-scio 你的package.json中是否有storybook作为依赖?
你能分享一下你的完整package.json吗?

sg2wtvxw

sg2wtvxw3#

你是否使用storybook CLI中的升级命令进行了升级?
参见:https://storybook.js.org/docs/configure/upgrading#upgrade-script

k0pti3hp

k0pti3hp4#

感谢您的回复。我无法分享完整的package.json文件,但相关部分如下:

--- a/package.json
+++ b/package.json
@@ -197,17 +197,17 @@
     "@playwright/browser-chromium": "1.45.0",
     "@pmmmwh/react-refresh-webpack-plugin": "^0.5.15",
     "@storybook/addon-coverage": "^1.0.4",
-    "@storybook/addon-docs": "8.1.11",
-    "@storybook/addon-essentials": "8.1.11",
-    "@storybook/addon-interactions": "8.1.11",
-    "@storybook/addon-viewport": "8.1.11",
+    "@storybook/addon-docs": "^8.2.4",
+    "@storybook/addon-essentials": "^8.2.4",
+    "@storybook/addon-interactions": "^8.2.4",
+    "@storybook/addon-viewport": "^8.2.4",
     "@storybook/jest": "^0.2.3",
-    "@storybook/preview-api": "8.1.11",
-    "@storybook/react": "8.1.11",
-    "@storybook/react-webpack5": "8.1.11",
-    "@storybook/test": "8.1.11",
+    "@storybook/preview-api": "^8.2.4",
+    "@storybook/react": "^8.2.4",
+    "@storybook/react-webpack5": "^8.2.4",
+    "@storybook/test": "^8.2.4",
     "@storybook/test-runner": "^0.19.0",
-    "@storybook/types": "8.1.11",
+    "@storybook/types": "^8.2.4",
     "@swc/core": "1.4.17",
     "@swc/helpers": "^0.5.12",
     "@swc/jest": "^0.2.36",
@@ -304,7 +304,7 @@
     "qs": "6.12.1",
     "semver": "^7.7.0",
     "sinon-chrome": "^3.0.1",
-    "storybook": "8.1.11",
+    "storybook": "^8.2.4",
     "storybook-addon-pseudo-states": "^3.1.1",
     "storybook-addon-swc": "^1.1.9",
     "storybook-dark-mode": "^4.0.2",

运行 npx storybook@latest upgrade 生成了相同的差异。

w9apscun

w9apscun5#

当我们从8.1升级到8.2时,在运行测试时也遇到了类似的问题:

Cannot find module 'storybook/internal/preview-api' from '../../node_modules/@storybook/react/dist/index.js'

这发生在一个pnpm工作区中,当使用pnpm检查时,所有storybook的内容都是8.2.4,迁移已经运行。
似乎package.json中的导出没有被使用。

nwwlzxa7

nwwlzxa76#

根据这些差异,我无法判断出了什么问题。
我确实需要一个复现来找出问题所在。
目前我唯一的想法是webpack中的某个东西阻止了export-map的使用/尊重。
这可能是webpack配置,或者是过时的webpack版本,这是我最好的猜测。

gzszwxb4

gzszwxb47#

是的,我理解需要一个复现环境,但遗憾的是它不是一个公共仓库,所以我不能分享。
会检查是否更新webpack是否有帮助。

bq3bfh9z

bq3bfh9z8#

@johannesgoslar-synth 你能分享一些更多的信息吗?例如:

npx storybook info - 环境和storybook包的版本
npx storybook doctor - 对你的项目的检查

也许分享一下你的package.json/main.ts等文件的一些内容。

相关问题