-
-
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
preset-create-react-app all files need to be in a src/ #9514
Comments
@Nber1 can you elaborate on what you'd like to see changed? Happy to bump the version to 2.0.0. |
Please revert 1.5.2 and publish the part above as 2.0.0 so it is clear where the breaking change happened. |
cc @mrmckeb |
@Nber1, first I understand you're frustrated - but (unless I'm mistaken) this is not a breaking change for users that use Create React App using defaults. However, we do our best to support the various ways people use CRA, and we certainly would have released this as breaking if we expected it to break any known uses. Can you please provide more information? What files do you have outside of In the meantime, please use the previous version and @shilman and I will look to update this soon as you can provide additional information. |
The company I work for never used a |
@Nber1 it's not possible to use a different folder (other than Or do you mean that your stories live outside of |
IMO, it should be marked as a breaking change by defintion, because you are changing something optional to be required, even if it won't affect anybody it should be marked as one. |
Thanks for the feedback - can you please show me which line you're referring to, @Nber1? I saw that you wrote (but removed) the following too:
Does that mean this is not an issue for you? |
No, the issue is, that I need to include all files in
EDIT: I am still talking about this lines added in the last commit: |
@Nber1 can you please give us some information about your project set up - what files are outside of src? How do they work with CRA now? A demo repository would be brilliant, but a written description would be enough. Thanks! |
@Nber1 , As a quick fix: You could also fixate "@storybook/preset-create-react-app": "1.5.1" in your package.json - this is the version before the change. Best regards |
Hi @Nber1 and @noelblaschke, if either of you can provide a repro repo, I can take a look and try to find a solution for you. Just let me know! |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
We have the same problem. We use the "js" folder instead "src" and we have follow errors:
It's work fine in "src" folder but not in other. |
I am also seeing this issue. I made an app today with
And changed the appropriate line in |
I am also seeing this issue when I use error
project
preview.js
version
|
@ldeveber I don't recommend that approach - I find it's generally better to keep stories and tests alongside components. It makes things easier contextually, and developers are more likely to keep tests/stories updated as they make changes. As mentioned, Storybook is using CRAs Webpack config here... so folders outside of src won't be processed and you'll need to modify the Webpack config yourself. |
@lucasleelz Again these need to be in src I believe. You could modify the Webpack config if you need support for folders outside of |
@mrmckeb but, 6.0.0 support for folders outside of src and .storybook. |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook! |
My case (may not very common, it has a real project in https://github.com/pingcap-incubator/tidb-dashboard/tree/master/ui), the following is the project files structure:
The project is initialized by CRA and typescript, then uses react-app-rewired and customized-cra to customize webpack config. I init the storybook by Then I add a new story in the src/stories/2-MetricChart.stories.tsx , the component imports the MetricChart from "../../lib/components", then I get the following error:
Then I put the story in the same place as the responding component under the lib/components folder. It looks like the following:
Also, change the The index.stories.tsx likes this:
Then I get the following error:
@mrmckeb , please help have a look, thanks in advance! |
According to the documents in https://storybook.js.org/docs/basics/writing-stories/#story-file-location , it says components and stories can put outside src, but why actually it can't? (Or this diagram is not correct? It seems it looks different when you copy and paste it by text)
|
hi @mrmckeb , how can we do it for storybook, I mean modify webpack config. |
Resolve the compile errors by following main.js config:
Now it works fine after running
But, there is still runtime error: I have no idea why this error happens. The full commit is here: pingcap/tidb-dashboard@d6b4d37 |
downgrade to 5.3 still has the same error, finally, changing my code writing way fixes it:
Full commit is here: pingcap/tidb-dashboard@27499af |
A reference to handle files outside It works for my project with following config:
Full commit: pingcap/tidb-dashboard@4bac5a6 |
btw, @shilman @mrmckeb can you fix this on the document site page? it really misguided the reader. Create an issue for it: #11573 |
Create React App simply doesn't support files outside of You can, if you wish, modify/override the preset (using Personally, I always keep stories alongside their components as I think this is a logical way to structure code - I do the same with unit tests - but we understand that people have different opinions and as I said, you can certainly change the config to support whatever you need. |
The following worked for me. It removes the plugin that enforces the "under src/" rule. module.exports = {
stories: ['../src/components/*.stories.*'],
addons: [
'@storybook/preset-create-react-app',
'@storybook/addon-essentials',
],
webpackFinal: (webpackConfig) => {
const scopePluginIndex = webpackConfig.resolve.plugins.findIndex(
({ constructor }) =>
constructor && constructor.name === 'ModuleScopePlugin',
)
webpackConfig.resolve.plugins.splice(scopePluginIndex, 1)
return webpackConfig
}
} |
@mrmckeb
From my experience, this concept put fourth by StoryBook is directly against a rationale that led most Frontend architects in in search of a system like StoryBook. Every project, I have been involved with, has wanted to develop an environment for separating components in one repo from the scaffolding in another repo of a frontend architecture solution. Several versions ago, v3 or 4, a shop where I was developing finally got the issues worked out. We were able to use re-wire and webpack to sustain a front-end structure that would allow developer to create components in the storybook directory/repo, and import them into the scaffolding directory/repo seamlessly during development . When we were ready to release we pushed both our latest version of the repo's new and updated components, and the front-end scaffolding repo and let the build take place in the code pipeline, treaty the StoryBook component as a library module handle by package.json. The 2 top reasons this was super useful:
I stopped advocating for StoryBook as a front-end architect, when I began using TypeScript to build React applications and could not easily enable this standalone repo approach. As I recall the issue involved incompatibilities stemming from re-wire or other complexities that made just to hard to set this separate repo approach. Once again, I am leading an effort where the UX folks really want to import their figma specs and images into StoryBook. I am going to give craco a go and see if I can recreate this. It would really be helpful if storybook had an example repo(s) of how this storybook standalone approach in one repo with an external repo could be approached. I have gone down the path of trying to use bit but that is just way to much overhead. Bits main advocacy stems from there understanding that this is what many developers want but can't achieve with storybook. |
@willTastyMakers I'm sorry, I think you've misunderstood what we're advocating here. We're not saying that you can't or shouldn't have a separate repo for components, and we're not saying that you can't place you stories where you want. Specifically, perhaps unclearly, I've said:
I'm one of both the CRA and Storybook teams (although I've been less active lately) and I can assure you that there are a number of ways to make this work. As an example, one of the projects we have in my company is a monorepo, and we have a For convenience, we added a root module.exports = (api) => {
api.cache(true);
return {
plugins: ['styled-components'],
presets: [
[
'react-app',
{
flow: false,
typescript: true,
},
],
],
};
}; Storybook now has built-in TypeScript support, but we wanted to just use our config based on CRA. The Storybook Webpack config looks like this, and lives in the package where the components live: module.exports = ({ config }) => {
const newConfig = config;
newConfig.module.rules[0].test = /\.(mjs|jsx?|tsx?)$/;
newConfig.module.rules[0].use[0].options.presets = [];
newConfig.module.rules[0].use[0].options.plugins = [];
newConfig.resolve.extensions = [...config.resolve.extensions, '.ts', '.tsx'];
return newConfig;
};
With newer versions of Storybook, you actually get out-of-the-box support for TypeScript. Unfortunately, the reality is that some people will always need more than Storybook does out of the box. In my company, we customise our configs as we want Storybook to share the build config for that package - to ensure things don't work in Storybook, and then fail in the app (and vice versa). The CRA preset takes the same approach (by default) - if it doesn't work in CRA, it won't work in Storybook. That doesn't mean we are refusing to add support for tools like craco/rewired/etc. @shilman and I have discussed this before and we're very open to adding support - we're very open to PRs to add support for one or many of these into the preset. In the meantime, you can always override Storybook's default Webpack config (or even build a reusable preset to do that). |
This is my solution. Maybe could be better but it works. I'm on @storybook/react v6.4.22
|
@bard How do I donate money to you or your project. Thank you! |
You are forced to include all files in a /src file
What the hell happened here?
That's clearly a breaking change and as it looks has nothing to do with the bug which the commit links to.
The text was updated successfully, but these errors were encountered: