question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Storybook addon: Module parse failed: Unexpected token

See original GitHub issue

Description

Using @chakra-ui/storybook-addon, start-storybook doesn’t work.

Link to Reproduction

https://codesandbox.io/s/chakra-storybooks-addon-error-pfy7pn

Steps to reproduce

  1. Run npm run start to start storybook
  2. Storybook doesn’t start and error is displayed

Chakra UI Version

2.2.6

Browser

Microsoft Edge

Operating System

  • macOS
  • Windows
  • Linux

Additional Information

I get multiple errors of the form:

ERROR in ./node_modules/@chakra-ui/storybook-addon/dist/preset/decorators.cjs.js 87:76 
Module parse failed: Unexpected token (87:76) 
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. 

I tried using the workaround mentioned in the docs

module.exports = {
  stories: ["../src/**/*.stories.@(j|t)sx"],
  addons: ["@storybook/addon-essentials", "@chakra-ui/storybook-addon"],
  framework: "@storybook/react",
  features: {
    emotionAlias: false
  },
  webpackFinal: async (config) => {
    config.module.rules.push({
      test: /\.mjs$/,
      include: /node_modules/,
      type: "javascript/auto"
    });

    return config;
  }
};

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:22
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

11reactions
opeahcommented, Aug 14, 2022

Same problem for me with "@chakra-ui/storybook-addon": "^4.0.8"

ERROR in ./node_modules/@chakra-ui/icon/dist/index.esm.js 58:28
Module parse failed: Unexpected token (58:28)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|     __css: styles
|   };
>   const _viewBox = viewBox ?? fallbackIcon.viewBox;
|   if (element && typeof element !== "string") {
|     return /* @__PURE__ */ React.createElement(chakra.svg, {

I’m using @storybook/builder-vite

10reactions
nk18chicommented, Sep 10, 2022

I had the same error but It is working in my environment when I use “webpack5” as the builder.

Here is the error I got.

ERROR in ./node_modules/@chakra-ui/storybook-addon/node_modules/@chakra-ui/icon/dist/index.esm.js 58:28
Module parse failed: Unexpected token (58:28)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|     __css: styles
|   };
>   const _viewBox = viewBox ?? fallbackIcon.viewBox;
|   if (element && typeof element !== "string") {
|     return /* @__PURE__ */ React.createElement(chakra.svg, {

package.json

    "@chakra-ui/icons": "^1.1.7",
    "@chakra-ui/react": "2.0.0-next.5",
    "@chakra-ui/storybook-addon": "2.0.0-next.4",
    "@storybook/addon-actions": "^6.5.10",
    "@storybook/addon-essentials": "^6.5.10",
    "@storybook/addon-links": "^6.5.10",
    "@storybook/react": "^6.5.10",
  1. Install packages
yarn add -D @storybook/builder-webpack5 @storybook/manager-webpack5
  1. Add builder in .storybook/main.js
module.exports = {
  ...
  core: {
    builder: 'webpack5',
  },
  1. Don’t forget to add theme in .storybook/preview.js
const theme = require('../path/to/your/theme')

export const parameters = {
  ...
  chakra: {
    theme,
  },
}

Reference https://stackoverflow.com/questions/70595004/chakra-ui-is-not-loading-when-used-with-storybook?rq=1
https://github.com/chakra-ui/chakra-ui/issues/5977

I hope this will be helpful to someone.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Storybook error - "ModuleParseError: Module parse failed
[built] ModuleParseError: Module parse failed: Unexpected token (6:2) You may need an appropriate loader to handle this file type, currently no ...
Read more >
npm run build-storybook fails with "Module parse failed
javascript - npm run build-storybook fails with "Module parse failed: Unexpected token (20:25)" - Stack Overflow. Stack Overflow for Teams – ...
Read more >
Webpack - Storybook
Storybook is a frontend workshop for building UI components and pages in isolation. Thousands of teams use it for UI development, testing, and...
Read more >
“You may need an appropriate loader to handle this file type”
It's a weird error and i can't figure out what is causing it. I have an app with patternfly ... Module parse failed:...
Read more >
mi on Twitter: "これで動いた! https://t.co/3Pmrlb7Jsz" / Twitter
Next13 + Chakra で storybook が動かない〜動かない〜動かない〜動かない〜 ... Storybook addon: Module parse failed: Unexpected token · Issue ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found