webpack 为什么我在构建Storybook时会出现此错误

bsxbgnwa  于 2023-10-19  发布在  Webpack
关注(0)|答案(1)|浏览(166)

我刚刚在一个激动人心的Next.js项目中将Storybook从V6.5.9升级到V7.1.0。一切正常,但当我尝试构建我的故事书时,它抛出以下错误:

ERR! => Failed to build the preview
ERR! 1620.ba7f2216.iframe.bundle.js from Terser plugin
ERR! Unexpected token: punc ({) [webpack://../node_modules/@storybook/components/dist/index.mjs:195,5420][1620.ba7f2216.iframe.bundle.js:5264,5512]
ERR!     at js_error (/Users/mac/Documents/Next/vactory_next/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:550:11)
ERR!     at croak (/Users/mac/Documents/Next/vactory_next/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:1274:9)
ERR!     at token_error (/Users/mac/Documents/Next/vactory_next/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:1282:9)
ERR!     at unexpected (/Users/mac/Documents/Next/vactory_next/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:1288:9)
ERR!     at as_property_name (/Users/mac/Documents/Next/vactory_next/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:3076:20)
ERR!     at concise_method_or_getset (/Users/mac/Documents/Next/vactory_next/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:2729:20)
ERR!     at class_ (/Users/mac/Documents/Next/vactory_next/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:2685:22)
ERR!     at expr_atom (/Users/mac/Documents/Next/vactory_next/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:2514:23)
ERR!     at maybe_unary (/Users/mac/Documents/Next/vactory_next/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:3310:19)
ERR!     at expr_ops (/Users/mac/Documents/Next/vactory_next/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:3361:24)
ERR! 1620.98ef3ea2.iframe.bundle.js from Terser plugin
ERR! Unexpected token: punc ({) [1620.98ef3ea2.iframe.bundle.js:5264,5512]
ERR!     at js_error (/Users/mac/Documents/Next/vactory_next/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:550:11)
ERR!     at croak (/Users/mac/Documents/Next/vactory_next/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:1274:9)
ERR!     at token_error (/Users/mac/Documents/Next/vactory_next/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:1282:9)
ERR!     at unexpected (/Users/mac/Documents/Next/vactory_next/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:1288:9)
ERR!     at as_property_name (/Users/mac/Documents/Next/vactory_next/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:3076:20)
ERR!     at concise_method_or_getset (/Users/mac/Documents/Next/vactory_next/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:2729:20)
ERR!     at class_ (/Users/mac/Documents/Next/vactory_next/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:2685:22)
ERR!     at expr_atom (/Users/mac/Documents/Next/vactory_next/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:2514:23)
ERR!     at maybe_unary (/Users/mac/Documents/Next/vactory_next/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:3310:19)
ERR!     at expr_ops (/Users/mac/Documents/Next/vactory_next/node_modules/terser-webpack-plugin/node_modules/terser/dist/bundle.min.js:3361:24)
ERR! Critical dependency: the request of a dependency is an expression
ERR! Critical dependency: the request of a dependency is an expression
ERR! Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
ERR! Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
ERR! Error: => Webpack failed, learn more with --debug-webpack
ERR!     at /Users/mac/Documents/Next/vactory_next/node_modules/@storybook/builder-webpack5/dist/index.js:1:7618
ERR!     at /Users/mac/Documents/Next/vactory_next/node_modules/@storybook/builder-webpack5/node_modules/webpack/lib/HookWebpackError.js:68:3
ERR!     at Hook.eval [as callAsync] (eval at create (/Users/mac/Documents/Next/vactory_next/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
ERR!     at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/mac/Documents/Next/vactory_next/node_modules/tapable/lib/Hook.js:18:14)
ERR!     at Cache.shutdown (/Users/mac/Documents/Next/vactory_next/node_modules/@storybook/builder-webpack5/node_modules/webpack/lib/Cache.js:150:23)
ERR!     at /Users/mac/Documents/Next/vactory_next/node_modules/@storybook/builder-webpack5/node_modules/webpack/lib/Compiler.js:1229:15
ERR!     at Hook.eval [as callAsync] (eval at create (/Users/mac/Documents/Next/vactory_next/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
ERR!     at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/mac/Documents/Next/vactory_next/node_modules/tapable/lib/Hook.js:18:14)
ERR!     at Compiler.close (/Users/mac/Documents/Next/vactory_next/node_modules/@storybook/builder-webpack5/node_modules/webpack/lib/Compiler.js:1222:23)
ERR!     at /Users/mac/Documents/Next/vactory_next/node_modules/@storybook/builder-webpack5/dist/index.js:1:7570
ERR!  Error: => Webpack failed, learn more with --debug-webpack
ERR!     at /Users/mac/Documents/Next/vactory_next/node_modules/@storybook/builder-webpack5/dist/index.js:1:7618
ERR!     at /Users/mac/Documents/Next/vactory_next/node_modules/@storybook/builder-webpack5/node_modules/webpack/lib/HookWebpackError.js:68:3
ERR!     at Hook.eval [as callAsync] (eval at create (/Users/mac/Documents/Next/vactory_next/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
ERR!     at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/mac/Documents/Next/vactory_next/node_modules/tapable/lib/Hook.js:18:14)
ERR!     at Cache.shutdown (/Users/mac/Documents/Next/vactory_next/node_modules/@storybook/builder-webpack5/node_modules/webpack/lib/Cache.js:150:23)
ERR!     at /Users/mac/Documents/Next/vactory_next/node_modules/@storybook/builder-webpack5/node_modules/webpack/lib/Compiler.js:1229:15
ERR!     at Hook.eval [as callAsync] (eval at create (/Users/mac/Documents/Next/vactory_next/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
ERR!     at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/mac/Documents/Next/vactory_next/node_modules/tapable/lib/Hook.js:18:14)
ERR!     at Compiler.close (/Users/mac/Documents/Next/vactory_next/node_modules/@storybook/builder-webpack5/node_modules/webpack/lib/Compiler.js:1222:23)
ERR!     at /Users/mac/Documents/Next/vactory_next/node_modules/@storybook/builder-webpack5/dist/index.js:1:7570
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed.
Exit code: 1
Command: /usr/local/Cellar/node@16/16.20.0/bin/node
Arguments: /usr/local/Cellar/yarn/1.22.19/libexec/lib/cli.js storybook:build
Directory: /Users/mac/Documents/Next/vactory_next/apps/starter
Output:

info Visit https://yarnpkg.com/en/docs/cli/workspace for documentation about this command.

在我看来,它与Terser和Webpack有关。我试着用谷歌搜索这个错误,但没有任何帮助,不幸的是。有什么想法吗?

uhry853o

uhry853o1#

支持terser was added in august 2022的静态模块我已经将terser版本强制为最新版本,现在它构建时没有此错误。
package.json

"overrides": {
    "terser": "5.19.2"
  }

相关问题