storybook: error: 'Plugin 0 provided an invalid property of "default"' when using with React Native + TypeScript
If you are reporting a bug or requesting support, start here:
Bug or support request summary
Failing to compile when trying to use with React Native + Typescript:
yarn storybook start -p 7007 --metro-config $PWD/rn-cli.config.js
ERROR in ./storybook/addons.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Plugin 0 specified in "/Users/***/node_modules/babel-preset-react-native/index.js" provided an invalid property of "default" (While processing preset: "/Users/***/node_modules/babel-preset-react-native/index.js")
at Plugin.init (/Users/***/node_modules/babel-core/lib/transformation/plugin.js:131:13)
at Function.normalisePlugin (/Users/***/node_modules/babel-core/lib/transformation/file/options/option-manager.js:152:12)
at /Users/***/node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
at Array.map (<anonymous>)
at Function.normalisePlugins (/Users/***/node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
at OptionManager.mergeOptions (/Users/***/node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
at /Users/***/node_modules/babel-core/lib/transformation/file/options/option-manager.js:265:14
at /Users/***/node_modules/babel-core/lib/transformation/file/options/option-manager.js:323:22
at Array.map (<anonymous>)
at OptionManager.resolvePresets (/Users/***/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
@ multi ./storybook/addons.js ./node_modules/@storybook/react-native/dist/manager/index.js manager[0]
Steps to reproduce:
- Create a new react-native app:
react-native init test --template typescript - Setup typescript support :
cd test && node setup.js getstorybook- replace storybook command with
storybook start -p 7007 --metro-config $PWD/rn-cli.config.js - Run
yarn storybook
Please specify which version of Storybook and optionally any affected addons that you’re running
"@storybook/react-native": "4.0.0-alpha.2",
"@storybook/addon-actions": "4.0.0-alpha.2",
"@storybook/addon-links": "4.0.0-alpha.2",
"@storybook/addons": "4.0.0-alpha.2"
Screenshots / Screencast / Code Snippets (Optional)
.babelrc:
{
"presets": ["react-native"]
}
.tsconfig:
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"jsx": "react",
"lib": ["es6"],
"module": "es6",
"moduleResolution": "node",
"noEmit": true,
"noImplicitAny": true,
"target": "es2015"
},
"exclude": ["node_modules"]
}
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 11
- Comments: 36 (4 by maintainers)
also bumping these dependencies seems to have fixed it for me:
Replace your package.json to exactly code bellow:
{ "name": "reactunitytest", "version": "0.0.1", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "test": "jest" }, "dependencies": { "react": "16.4.1", "react-native": "0.55.0", "react-native-unity-view": "^1.1.2" }, "devDependencies": { "babel-jest": "23.4.0", "babel-preset-react-native": "2.1.0", "jest": "23.4.1", "react-test-renderer": "16.4.1" }, "jest": { "preset": "react-native" } }Restart your Metro bundle service and to be happy!
I was seeing this too on a new React Native (0.56) app, without TypeScript.
As mentioned elsewhere, the issue stems from the fact that RN 0.56 uses babel core v7, whereas the
getstorybookcommand installs babel core v6. To solve, this is what I did:This ensures that storybook uses the same version of babel core that RN is using to compile the app. The babel-core bridge package is necessary so that storybook ‘sees’ babel core v7 properly (see here for more details).
For those still running into this issue, here are the steps i followed to get updated:
"babel-preset-react-native": "^4.0.1"yarn installreact-native-git-upgradeyarn remove babel-preset-react-nativeyarn add -D metro-react-native-babel-preset"clear-cache": "watchman watch-del-all && rm -rf node_modules/ && yarn install && react-native start --reset-cache"That should do it! Let me know if this helps!
Downgrading to
^4.0.1did the trick to methe same error exist even without typescript
Just i changed “babel-preset-react-native”: “4.0.0” version and this issue is fixed.
Hey Guys I manage to get it working RN v0.57 and storybook,
react-native init@babel/runtimeso I installed(IDK if this will happen to you as well)getstorybooknode_modulesand rannpm start -- --reset-cacheproblem solved,yarn run storybookI wasn’t able to see the stories.So I modify my index.js to something like this:
With all this steps I was able to meke it run, I hope it helps
@raynor85 I just followed the directions in https://github.com/storybooks/storybook/issues/3897#issuecomment-421186803 except for the
watchman watch-del-allpart because I don’t have watchman. The key I think was downgrading to"babel-preset-react-native": "^4.0.1"before I ranreact-native-git-upgrade. I had tried a million times upgrading to 0.57 before that and that was the only thing that I changed. Then it worked.Yep I also tried the same and 👎
@ivansnek it seems like we have the same issue. Storybook watcher is working but it is simply not connected to the simulator. I have also tried to create a fresh react-native project (version 0.57), but no luck.
@andycloke I am still stuck with the same issue with React Native (0.56) and typeScript, can you please help me out here is my config
devDependencies -
"@babel/core": "7.0.0-beta.47", "@storybook/addon-actions": "4.0.0-alpha.2", "@storybook/addon-links": "4.0.0-alpha.2", "@storybook/addon-storyshots": "4.0.0-alpha.2", "@storybook/addons": "4.0.0-alpha.2", "@storybook/react-native": "4.0.0-alpha.2", "babel-core": "7.0.0-bridge.0", "babel-preset-react-native": "^5", "babel-runtime": "^7.0.0-beta",.babelrc
{ "presets": [ "react-native" ] }Have tried the solution suggested by @fiznool, still haven’t got it working.
@hersonrodrigues thank you, your code ended my 2-days struggling about starting react native normally
i have the same issue, in a new project with the same setup as @andycloke. @jimmytb’s solution does not fix the error for me