The recommended settings cannot fix the problem when using storybook
See original GitHub issueWhen 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:
- Created 5 years ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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”
Thanks for the reproduction 😄
Jest doesn’t apply transforms to node_modules by default. You can solve this by changing the
transformIgnorePatterns
:Or adding to
moduleNameMapper
as you have suggested: