-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Storybook webpack not configured for Create React App 2.0 Inline SVG's #4298
Comments
+1 I ran into this as well, and @semb09's webpack config solved the problem. For anyone else coming across this, I also needed to add the referenced packages to my vanilla CRA+Storybook app:
|
I can relate it to #4306 as well. IMO, we need to support as much as possible for CRA2 compatibility. Does anyone want to take this as a PR? |
So I am trying to get this to work with typescript. // webpack.config.js
module.exports = (storybookBaseConfig, configType) => {
storybookBaseConfig.resolve.extensions.push(".ts", ".tsx");
storybookBaseConfig.module.rules[0].test = /\.(mjs|jsx?|tsx?)$/;
storybookBaseConfig.module.rules[0].use[0].options = require("./babel.config");
return storybookBaseConfig;
}; // babel.config.js
module.exports = {
presets: [
require.resolve("babel-preset-react-app"),
],
plugins: [
[
require.resolve("babel-plugin-named-asset-import"),
{
loaderMap: {
svg: {
ReactComponent: "@svgr/webpack?-prettier,-svgo![path]",
},
},
},
]
]
}; This will result in a warning like this
import is: What am I missing? |
Released in alpha: https://github.com/storybooks/storybook/releases/tag/v4.1.0-alpha.8 |
This does not work for me. Still getting the same warning/error:
this is the story: import React from "react";
import { IconStories } from "../../icons.story";
import { ReactComponent as Youtube } from "./youtube.svg";
IconStories.add("Youtube", () => <Youtube />); |
Do you have a reproduction? |
Unfortunately was not able to reproduce it. But thats great. |
Okay, so I was able to reproduce it by having:
In the config directory. Repo: https://github.com/Itrulia/storybook-svg-import-problem |
@Itrulia do you use CRA2? I wonder why would you create a custom webpack config, since we support now TS and svgr out of the box for CRA2 users. |
Yes, I am. Because I need more than CRA gives me so I override the config (I don't eject, override it ala https://github.com/timarney/react-app-rewired). Atleast with #4902 being merged I don't need to override it for Storybook. |
Do you have a |
Yes, you can checkout the repo I linked earlier. |
Ok, so the problem is that you should use module.exports = (storybookBaseConfig, configType, defaultConfig) => {
return defaultConfig;
}; default config has a rulse for svg, that is needed for SVGR later. |
Oh... This works great! Thanks and sorry for wasting your time! |
Linking the #4903 here. |
I'm currently getting an error regarding my inline svgs from storybook with CRA which version of storybook is this supported from? update nvm, I was using storybook |
If you are reporting a bug or requesting support, start here:
Bug or support request summary
I recently upgraded to Create React App 2.0 so that I could use the new SVG import feature
import { ReactComponent as Icon } from 'icon.svg';
I then realised that this is provided via react-scripts webpack config and that Storybook has its own config. I then updated to the latest alpha version of Storybook but it still did not work.
I managed to get the feature to work by adding the following to storybook webpack config file
Will this config be included in future Storybook updates?
Steps to reproduce
import { ReactComponent as Icon } from 'icon.svg';
syntax inside any component in a story(A screencast can be useful for visual bugs, but it is not a substitute for a textual description.)
Please specify which version of Storybook and optionally any affected addons that you're running
The text was updated successfully, but these errors were encountered: