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.

The recommended settings cannot fix the problem when using storybook

See original GitHub issue

When using storybook,

  transform: {
    '^.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
    // ... snip ...
  },

cannot fix the problem (Syntax Error: Invalid or unexpected token), but,

  moduleNameMapper: {
    '^.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
  },

can fix the problem. I’m not sure the reason.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jonasohrncommented, Dec 7, 2018

The same line in jest config as above fixed my problem which is unrelated to storybook: moduleNameMapper: { ‘^.+\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$’: ‘jest-transform-stub’, }, This was for the general problem that jest does not handle import of external css and I guess we need this stub both for local css (using transform config) but also add it to moduleNameMapper to stub transitive source dependencies imported css: myTest -> myComponent.vue -> import otherLibraryComponent.vue -> “import some.css”

1reaction
eddyerburghcommented, Jan 18, 2019

Thanks for the reproduction 😄

Jest doesn’t apply transforms to node_modules by default. You can solve this by changing the transformIgnorePatterns:

{
  jest: {
    // ..
    "transformIgnorePatterns": ["/node_modules/(?!your-module-name)"]
  }
}

Or adding to moduleNameMapper as you have suggested:

{
  jest: {
    "moduleNameMapper": {
      '^.+\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
    },
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Storybook v5 breaks when using core-js ^3.0 #6204 - GitHub
This happened after updating to node v12 using nvm. We had to do this to fix a polyfill issue so I can't downgrade...
Read more >
Configure Storybook
Configure your Storybook project. The main configuration file is main.js . This file controls the Storybook server's behavior, so you must restart Storybook's...
Read more >
@storybook/react - npm
If you're working on an app that was initialized manually (i.e., without the use of Create React App), ensure that your app has...
Read more >
Configuring Storybook: 6 Tips You Can't Miss | by Zheng Li
Tip 1: The Storybook has its default webpack configuration, when trying to import your current webpack config or add your own rules, DO...
Read more >
Storybook - no stories showing up in typescript project with ...
When trying to create a story from my components, I get the error: Module not found: Error: Can't resolve 'esri/Basemap' in '/.../GitHub/20-maps ...
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