storybook: babel-loader conflicts with create-react-app version
Describe the bug
After creating a new project with create-react-app yarn start
and yarn test
do not run.
There is a conflict with babel-loader version.
Changing the line in package.json to "babel-loader": "8.0.4"
seems to fix it.
To Reproduce Steps to reproduce the behavior:
- Start a project with
npx create-react-app taskbox
- Init storybook
npx -p @storybook/cli sb init
- Run
yarn test
Expected behavior Should run the tests.
Code snippets
npx create-react-app taskbox
Creating a new React app in /Users/aericson/projects/taskbox.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
yarn add v1.12.3
[1/4] š Resolving packages...
[2/4] š Fetching packages...
[3/4] š Linking dependencies...
[4/4] š Building fresh packages...
success Saved lockfile.
success Saved 5 new dependencies.
info Direct dependencies
āā react-dom@16.7.0
āā react-scripts@2.1.3
āā react@16.7.0
info All dependencies
āā react-dev-utils@7.0.1
āā react-dom@16.7.0
āā react-error-overlay@5.1.2
āā react-scripts@2.1.3
āā react@16.7.0
āØ Done in 75.22s.
Initialized a git repository.
Success! Created taskbox at /Users/aericson/projects/taskbox
Inside that directory, you can run several commands:
yarn start
Starts the development server.
yarn build
Bundles the app into static files for production.
yarn test
Starts the test runner.
yarn eject
Removes this tool and copies build dependencies, configuration files
and scripts into the app directory. If you do this, you canāt go back!
We suggest that you begin by typing:
cd taskbox
yarn start
Happy hacking!
ā projects cd taskbox
ā taskbox git:(master) npx -p @storybook/cli sb init
npx: installed 423 in 38.734s
[BABEL] Note: The code generator has deoptimised the styling of /Users/aericson/.npm/_npx/7855/lib/node_modules/@storybook/cli/node_modules/lodash/lodash.js as it exceeds the max of 500KB.
sb init - the simplest way to add a storybook to your project.
ā¢ Detecting project type. ā
ā¢ Adding storybook support to your "Create React App" based project. ā
ā¢ Preparing to install dependencies. ā
yarn install v1.12.3
[1/4] š Resolving packages...
[2/4] š Fetching packages...
[3/4] š Linking dependencies...
warning "@storybook/react > @emotion/styled > @emotion/styled-base@0.10.6" has unmet peer dependency "@emotion/core@0.x.x".
warning " > babel-loader@8.0.5" has unmet peer dependency "webpack@>=2".
[4/4] š Building fresh packages...
success Saved lockfile.
āØ Done in 58.11s.
ā¢ Installing dependencies. ā
To run your storybook, type:
yarn storybook
For more information visit: https://storybook.js.org
ā taskbox git:(master) ā yarn test
yarn run v1.12.3
$ react-scripts test
There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.
The react-scripts package provided by Create React App requires a dependency:
"babel-loader": "8.0.4"
Don't try to install it manually: your package manager does it automatically.
However, a different version of babel-loader was detected higher up in the tree:
/Users/aericson/projects/taskbox/node_modules/babel-loader (version: 8.0.5)
Manually installing incompatible versions is known to cause hard-to-debug issues.
If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.
To fix the dependency tree, try following the steps below in the exact order:
1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
2. Delete node_modules in your project folder.
3. Remove "babel-loader" from dependencies and/or devDependencies in the package.json file in your project folder.
4. Run npm install or yarn, depending on the package manager you use.
In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:
5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
This may help because npm has known issues with package hoisting which may get resolved in future versions.
6. Check if /Users/aericson/projects/taskbox/node_modules/babel-loader is outside your project directory.
For example, you might have accidentally installed something in your home folder.
7. Try running npm ls babel-loader in your project folder.
This will tell you which other package (apart from the expected react-scripts) installed babel-loader.
If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.
P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
ā taskbox git:(master) ā
Here are the versions installed:
npx create-react-app --version
2.1.3
and the versions that storybook added with `sb init`
"devDependencies": {
"@storybook/react": "^4.1.4",
"@storybook/addon-actions": "^4.1.4",
"@storybook/addon-links": "^4.1.4",
"@storybook/addons": "^4.1.4",
"@babel/core": "^7.2.2",
"babel-loader": "^8.0.5"
}
System:
- OS: MacOS
- Device: Macbook Pro 2018
- Framework: react
- Version: 4.1.4
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 174
- Comments: 155 (51 by maintainers)
Commits related to this issue
- Add storybook https://github.com/storybooks/storybook/issues/5183 Explicitly set the version of babel-loader to 8.0.4 — committed to wafflestudio/snutt-webclient by zxzl 5 years ago
- Bundle using create-react-app 2 (#24) * Copy source files onto CRA created package * Copy serviceWorker setting * Enable Sass support * Copy and paste dependencies * Append REACT_APP_ pre... — committed to wafflestudio/snutt-webclient by zxzl 5 years ago
- work-around babel-loader dependency conflict see https://github.com/storybooks/storybook/issues/5183 — committed to kagia/speedread by kagia 5 years ago
- Fix storybook babel-loader missing dependency See [Issue 5183](https://github.com/storybooks/storybook/issues/5183) — committed to MaurizioVacca/ui-demo by deleted user 5 years ago
- Add styled component, storybook, prettier The @babel/core & babel-loader dependencies are for storybook & should be removed once storybook fixes these required dependencies. Related tickets + resour... — committed to stephenkoo/cotrii-web by stephenkoo 5 years ago
- Babel loader bug fixed with https://github.com/storybookjs/storybook/issues/5183#issuecomment-4987 — committed to metamn/inu-v2-a by metamn 5 years ago
- :ambulance: Fix babel-loader dependency issue between storybook and cra More Information: https://github.com/storybookjs/storybook/issues/5183#issuecomment-726724306 — committed to mhstrkmp/awesome-project-template by mhstrkmp 4 years ago
- fix babel-loader conflicts with create-react-app and storybook reference: https://github.com/storybookjs/storybook/issues/5183#issuecomment-726882161 — committed to yuizho/chambre by yuizho 3 years ago
- fix babel-loader conflict with storybook https://github.com/storybookjs/storybook/issues/5183 — committed to chrisirhc/modular-ramp by chrisirhc 3 years ago
- fix (storybook): add rule to disable preflight check because babel-loader used by storybook is confliting with the version used by create-react-app (https://github.com/storybookjs/storybook/issues/518... — committed to brunaschneiders/dc.front.devtest by brunaschneiders 3 years ago
- build: fix babel conflict https://github.com/storybookjs/storybook/issues/5183 — committed to TalismanSociety/talisman-web by tien 2 years ago
- build: fix babel conflict https://github.com/storybookjs/storybook/issues/5183 — committed to TalismanSociety/talisman-web by tien 2 years ago
- build: fix babel conflict https://github.com/storybookjs/storybook/issues/5183 — committed to TalismanSociety/talisman-web by tien 2 years ago
Confirming that this is still an issue with the latest versions of creat-react-app and storybook.
Edit: create-react-app will complain about an incorrect babel-loader version in node_modules. I was able to resolve the issue using
yarn add -D --exact babel-loader@8.1.0
, which was the version that CRA required.You should add a resolution dependencies in your package.json file :
UPDATE : Has @newmandani said, this solution work only if you use yarn
"resolutions": { "babel-loader": "8.1.0" }
@ayoola-moore Yes, the workaround is to change the line in
package.json
to:This way both
react-scripts
andstorybook
will work. Still looking into a better solution. šcc @artisologic @YoannDelpierre @ovionlogis @patricknick @mrmckeb @ivnkld @viniciusreiss @dlevs @Jipperism @euskonadox @fuadajip @AMTourky @greatermeans @tmeasday @Eugene-Sviridov @nerfologist
Adding a resolutions to my
package.json
on a Yarn project was the best solution for me, because you can see later that youāre applying a fix and when this finally gets resolved you can remove it.@shilman FYI Iām still getting this issue with
6.1.20
:Very thanks @DylanCulfogienis , you saved my day!! I spend hours to remove and install storybook and even the hold node_modules dir again and agian, and
yarn add -D --exact babel-loader@8.1.0
did work!What happen engineers? Do u need help with this huge error? XD A big project that not works no helps so much!
Still an issue with
"@storybook/react": "^6.3.9"
and"react-scripts": "4.0.3"
, no babel-loader in package.jsonHmm when I remove
babel-loader
dep then storybook breaksā¦ šHi, unfortunately, upgrading storybook dependencies to alpha versions with
npx sb upgrade --prerelease
didnāt do the trick, thereās still the samebabel-loader
issue.I was able to bypass it by using one of the following hacks:
Or adding ābabel-loaderā: ā8.1.0ā explicitly to the dev dependencies in the
package.json
even thoughreact-scripts
andstorybook
already havebabel-loader
es a dependency.Or adding
SKIP_PREFLIGHT_CHECK=true
to the.env
file.Iām using the latest
create-react-app ("react-scripts": "^4.0.3")
andstorybook ("@storybook/react": "^6.3.6")
.Sadly, they are hacks and are not recommended to use since it creates other hard to debug bugs.
@DylanCulfogienis solution fixed it for me as well, after a half-day battle. Thereās another command from https://github.com/storybookjs/storybook/issues/12408 wrapped up in here, but this is the setup that got me going:
Also ran into this when installed CRA v4 with SB v6.1:
It can work for yarn only.
This is still an issue on fresh installs of the latest CRA/SB versions (4.0.1 and 6.1.18, respectively, at the time of this writing).
Make sure you remove the leading ā^ā otherwise you will still get 8.0.5
This is still an issueā¦
Huzzah!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.4.0-alpha.23 containing PR #14811 that references this issue. Upgrade today to the
@next
NPM tag to try it out!Closing this issue. Please re-open if you think thereās still more to do.
They should be forced to use either or, not both at the same time in the same project
Please i really need help.
i try everything but enything work.
`There might be a problem with the project dependency tree. It is likely not a bug in Create React App, but something you need to fix locally.
The react-scripts package provided by Create React App requires a dependency:
ābabel-loaderā: ā8.0.5ā
Donāt try to install it manually: your package manager does it automatically. However, a different version of babel-loader was detected higher up in the tree:
c:\Users\Z-Dra\node_modules\babel-loader (version: 8.0.6)
Manually installing incompatible versions is known to cause hard-to-debug issues.
If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project. That will permanently disable this message but you might encounter other issues.
To fix the dependency tree, try following the steps below in the exact order:
In most cases, this should be enough to fix the problem. If this has not helped, there are a few other things you can try:
If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead. This may help because npm has known issues with package hoisting which may get resolved in future versions.
Check if c:\Users\Z-Dra\node_modules\babel-loader is outside your project directory. For example, you might have accidentally installed something in your home folder.
Try running npm ls babel-loader in your project folder. This will tell you which other package (apart from the expected react-scripts) installed babel-loader.
If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project. That would permanently disable this preflight check in case you want to proceed anyway.
P.S. We know this message is long but please read the steps above š We hope you find them helpful!
npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! mrfox@0.1.0 start:
react-scripts start
npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the mrfox@0.1.0 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\Z-Dra\AppData\Roaming\npm-cache_logs\2019-05-29T12_53_58_726Z-debug.log`
Please some one can help me?
Using
"react-scripts": "2.1.8"
andstorybook
v5, Iām getting the same error. As stated by others, manually adding"babel-loader": "8.0.4"
as adevDependency
fixed it.@GabrielModog I ended up using Yarn
resolutions
. However, Iām not sure if itās the safes one.Iām not a fan of adding
SKIP_PREFLIGHT_CHECK
to the.env
because it will skip other checks. And, also the whole team needs to do that manually.Adding
babel-loader
explicitly to thepackage.json
also seemed to not work for every team member.Surprised that this issue still isnāt resolved. Isnāt storybook + CRA a super common setup?
Edit: adding
"babel-loader": "8.1.0"
to my deps somehow fixed it now. Which is really weird considering when I checknpm ls babel-loader
I can see that 8.2.2 is still used in some places. But not gonna complain lol.How come this issue still exists for 2 years?!
Good golly!! I just released https://github.com/storybooks/storybook/releases/tag/v5.1.0-alpha.25 containing PR #5308 that references this issue. Upgrade today to try it out!
Because itās a pre-release you can find it on the
@next
NPM tag.Closing this issue. Please re-open if you think thereās still more to do.
+1 I have the same issue with CRA and
"@storybook/react": "^6.1.21",
Same problem here : React 4.0.1 and
PS : Should we open a new issue as it concern different version of the same problem ?
The
npm
equivalent would be to useoverrides
:Though you need npm >= 8.3
Hello, I am a CRA user and faced this problem when I initialized storybook by the following command described in the document for React.
Then, I fixed the problem by initializing with the following.
(And the automatic detection without
--type
option was also successful. cool!)I think this is a lack of documentation and can make such kind of mistakes. Please add explanation about
--type react_scripts
to the Storybook for React page or create a separate tutorial for CRA.Thanks!
Just in case anyone else lands in the same situation as me: I couldnāt for the life of me get the Storybooks + CRA integration to work, where Storybooks uses the build setup of CRA. However, I then tried to move my stories into the
src/
directory of my CRA project, and suddenly it worked. I donāt know why, or if it has been recommended or required all along, but this fixed it for me.Any updates about this one? canāt solve it by just adding
"babel-loader": "8.0.4"
or any of the other stepsStill having the same issue
Hi. Will someone kindly tell me how to unclone a computer? My āfriendā is a fuckwad.
Get Outlook for Androidhttps://aka.ms/AAb9ysg
From: Klaus Kazlauskas @.> Sent: Monday, September 26, 2022 12:15:57 PM To: storybookjs/storybook @.> Cc: Subscribed @.***> Subject: Re: [storybookjs/storybook] babel-loader conflicts with create-react-app version (#5183)
The npm equivalent would be to use overrides:
āoverridesā: { ābabel-loaderā: ā8.1.0ā }
Though you need npm >= 8.3
This worked for me. I also needed to override the webpack version like this:
{ āoverridesā: { ābabel-loaderā: ā8.1.0ā, āwebpackā: ā4.44.2ā } }
Iām using Storybook v6.5.0, react-scripts v4.0.3, and React v16.13.0.
ā Reply to this email directly, view it on GitHubhttps://github.com/storybookjs/storybook/issues/5183#issuecomment-1258363433, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ARIPUD4I3N4O2TPD3BMTTNTWAHK43ANCNFSM4GOW77AQ. You are receiving this because you are subscribed to this thread.Message ID: @.***>
Can confirm Iām also running into this, Can we reopen this issue? I dont really want to have to include babel-loader in my package if im not using it my self? I can confirm @DylanCulfogienis fix works though!
Thanks guys, Iāll make a note to update that documentation.
FYI weāve got some game-changing work on CRA support coming from @mrmckeb ā hopefully will make reasoning about these issues a lot easier
@revmischa Babel is how you can use TypeScript. The TS team give two paths - the TypeScript compiler, or a Babel plugin.
@rlecaro2 and @Akaryatrh, we made a change some months ago, where in the latest Storybook releases, babel-loader is not installed alongside CRA, and is instead found from within CRA.
As I understand it, you have no issues at all - apart from the fact that files within
.storybook
are not being processed correctly. This is because Create React Appās config ignores files outside of source.We made a small change to allow for TypeScript inside the
.storybook
directory here, and could do the same for the rest of the config. Iām assuming youāre both not using TypeScript which is why that fix didnāt work for you.Iām a little confused why that
devDependencies
fix works thoughā¦ I think that also needs investigation.Also note that this is a new issue, not related to the above. As comments here alert all users, Iāve created a new ticket here: #7201. Please add details there.
@vipyoshi A couple comments:
--type react
. Let it use the CRA template instead.@storybook/cli@next
and weāre releasing that as stable in the next 24h.Updating react-scripts worked for me (thx, @nguyentuandat). I was on 2.1.1, updated with instructions from the changelog:
The workaround doesnāt seem to work for me. I still see the conflicts after trying the workaround.
upgrading to react-scripts v5 fixed this for me
@egor-xyz I have the same
webpack
issue after I addedbabel-loader
in resolutions, so I add CRA required version ofwebpack
inresolutions
as well. Not sure if this is a good solution but it solves the issue for me.Mine is
"@storybook/react": "^6.4.9"
and"react-scripts": "3.3.0"
Fixed in #13607 and available in 6.1.12 / 6.2.0-alpha
Basic Setup without Typescript does not even work for me
npx create-react-app my-app
cd my-app
npx -p @storybook/cli sb init --type react
CRA expects
"babel-loader": "8.0.5"
but finds8.0.6
. However the generatedpackages.json
hsa following devDependencies listed:Setting the version to
"babel-loader": "8.0.5"
does resolve this issue.Also I have a similar Issue in another project where CRA (3.0.1) expectes
"webpack": "4.29.6"
but finds4.32.2
. That is not defined in my dependecird inside thepackage.json
npm ls webpack
shows:Storybook@5.0.11 provides a newer version of webpack, but CRA wants an older version. Adding
webpack@4.29.6
to the dependencies does fix it. Not quite sure if this is an issue with storybook thouā¦I changed version from
2.1.2
to2.1.5
then it resolvedI have been through the same issue and finally fixed it. I changed the babel-loader back to "8.0.4"in my package.json file and needed to delete the package-lock json file and I was then able to start and test with storybook. I hope this is helpful.
Thatās it. It will fix the issue.
@AlexMachin1997 They (
create-react-app
) removed their dependency check that assumed their dependencies would be hoisted to the root ofnode_modules
in https://github.com/facebook/create-react-app/pull/11474This appears to be fixed in CRA5. Iām closing this for now. Please let me know if thereās more to be done here!
When Iām changing ābabel-loaderā: ā8.1.0ā - Iām getting the same issue with
webpack
:.../node_modules/webpack (version: 4.46.0)
Solve
"@storybook/react": "^6.4.9"
and"react-scripts": "4.0.3"
with thisHowever if I use
npm
to install"@storybook/react": "^6.4.9"
and"react-scripts": "4.0.3"
, then no workaround needed, thenpm
resolves thebabel-loader
to be8.1.0
This is an issue for me as well, and Iām not even using yarn.
I have a lerna monorepo with npm. There are two sibling packages. One component library with storybook, the other made with create react app. Latest versions of everything.
When I try to import the babel-transpiled component library into the CRA, I get the error listed in this issue.
I have to manually set the version:
babel-loader: 8.1.0
to get rid of the issue. (Whereas it automatically installed at ^8.2.2.I have to hoist the dependencies to avoid the duplicate react issue. But if I do then I have to deal with this babel-loader version issue.
I am experiencing this too. My question is: does the
babel-loader
version used instorybook
really have to be^8.2.2
or can it just be lowered a bit? If it was^8.0.0
or something then this wouldnāt be an issue.I tried adding the
babel-loader
dep exactly and explicitly, that produced no changes for the better. I then added theyarn
resolution, and that works with CRA and Storybook - which makes me wonder, why doesstorybook
insist on a newer version than other key packages require? This would be a very easy fix to at least add compatibility with current versions ofcreate-react-app
.EDIT: I see thereās a build error in Storybook:
So it looks like there is an incompatibility, but it doensāt actually stop storybook from running. interesting. But that goes away if I just run
So presumably if that were just added as a dependency alongside loosening the dependency, things might just be peachy.
1 possible workaround is to add babel-loader@8.1.0 to dependencies in package.json. Another is to add SKIP_PREFLIGHT_CHECK=true to .env.
Just confirming that Iām still stumbling on this issue as of the date of my post and that @DylanCulfogienis solution of explicitly installing babel-loader solved it. Iām also using a yarn monorepo with a āwebā package for the react application but did not stumble on the problem described by @cjmyles, possibly unrelated?
@mrmckeb I think itās more about only finding
but not
in the docs when looking at:
so you think youāre doing everything correct by using
--type react
when you have a CRA repo.using
--type react
led toCannot find module 'babel-jest'
errors ---type react_scripts
is working out of the box.@aericson, sorry for the inconvenience. Iāll look today.
Note, this is in the advanced config. It says:
Iāll update to mention CRA too.
@isenese, sorry I have been out of action a bit recently.
This is resolved in new versions of Storybook, or at least should be - please provide version details if youāre still facing this and we can help out.
@ramonex1
Yes for me itās just a stupid think.
Itās another node modules in my folders
Great! Iāll try to figure out whatās making the dev dependency work. Just for anyone else, the issue is #7201 (minor typo).
@shilman @mrmckeb with the latest version:
JSX syntax is not transformed in
.storybooks/config.js
andstart-storybook
fails with a syntax error (on the first<
).Using the previous workaround of having babel-loader installed but with the version in sync with CRA works fine.
I tried to check if CRA uses
babel-preset-react
in some but not all folders but didnāt get anywhere.For context, Iām using CRA 3.0.1 and havenāt ejected.
What else could be the issue (should I open one)? How can I help?
PS: Iām using a decorator for global styles btw.
I discovery that I have
babel-loader 8.0.6
installed globally on my home directory/home/user/node_modules
, so under my project directory was installed babel-loader 8.0.5, so I removenpm remove babel-loader
on my home directory(8.0.6), than all work fine.Looks like I had a different version in a project in an enclosing folder.
@mrmckeb I just released
@storybook/preset-typescript
and need to update the typescript docs anyway. If you let me know what I should say about Typescript and CRA, Iād be happy to work that into the update. Thanks! šI just tried the latest beta build. We are using storybook with
react-scripts@3.0.1
and the Typescript setup described here: https://storybook.js.org/docs/configurations/typescript-config/#setting-up-typescript-with-babel-loaderThis fails though as the require cannot find the CRA babel-loader. Is there already a solution for that?
Yes, this is a good workaround for now @nguyentuandat, but only temporary until we work out how to handle this properly.
Thanks @oscargws, weāre actively investigating this and #5308 was raised to solve this. @ndelangen, can you take a look at that PR?
I was able to get the work around working. Thanks
Same issueā¦ any workaround yet?
Having the same issue š