Comments (13)
Try adding the babel plugin for optional chaining https://babeljs.io/docs/babel-plugin-transform-optional-chaining
from storybook.
@dannyhw Is that something that should be supported out of the box in a recent version of RN?
from storybook.
This is already included in preset env, I wouldn't expect to see this in most projects. The repro is using an old version of the react native babel preset which could be a cause.
from storybook.
Try adding the babel plugin for optional chaining https://babeljs.io/docs/babel-plugin-transform-optional-chaining
I tried installing @babel/transform-optional-chaining
and added it to the babel config, but the problem remains.
from storybook.
This is already included in preset env, I wouldn't expect to see this in most projects. The repro is using an old version of the react native babel preset which could be a cause.
I tried bumpingmetro-react-native-babel-preset
to the latest version, and installing @babel/preset-env
but none of it seems to help.
We already use lots of optional chaining operators in our code base, with no issues, this issue is only happening when we're building a minified bundle that includes Storybook.
Also, the file that it refers to seems to be minified already, and there's no such (?) operator on line 39, as suggested by the error message. The file looks like this.
![image](https://private-user-images.githubusercontent.com/426051/333792276-72b2e087-5c4e-4258-88e0-e0a110dc2215.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg0NjMwNjYsIm5iZiI6MTcxODQ2Mjc2NiwicGF0aCI6Ii80MjYwNTEvMzMzNzkyMjc2LTcyYjJlMDg3LTVjNGUtNDI1OC04OGUwLWUwYTExMGRjMjIxNS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNjE1JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDYxNVQxNDQ2MDZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT03N2E2OTljODhlZTE0MmY3N2RmMmQxODliNjVmYWE5YmMzNGNkNjBjYjU0NjI5MzcyNzU5ZGU3NDRhY2FhNDg4JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.ZILSu3ByMz4SMrCNHQ7aH8h_U0naSjHlOj6ygn3RrDo)
from storybook.
@esbenvb react native uses a different package for the babel plugin now its @react-native/babel-preset, not sure which version that changed though
if the ? is inside a string then maybe its the ` which doesn't get parsed correctly 🤔 however I'm not sure it is that line which causes it
from storybook.
@esbenvb the unstable_useRequireContext option requires at least react native 0.72 so you wont be able to use v7.6 on v70 of react native. You should try to at least update to 0.72.
from storybook.
I've tested on https://github.com/dannyhw/react-native-storybook-starter and the bundle command works fine
from storybook.
@esbenvb the unstable_useRequireContext option requires at least react native 0.72 so you wont be able to use v7.6 on v70 of react native. You should try to at least update to 0.72.
I'm not sure this is true.
If I leave out unstable_useRequireContext
in my project, I get the error below, when starting the bundle server (yarn start
). But works well with this transformer setting in metro config.
And as I said, Storybook seems to work fine in my 0.70.x project, both in debug and release. The ONLY case that cause trouble us when with minify enabled.
We're not just gonna upgrade RN soon, but If you think that v7.6 is too new for my RN version, what version would you recommend that works with RN 0.70?
ERROR Error: The experimental Metro feature `require.context` is not enabled in your project.
This can be enabled by setting the `transformer.unstable_allowRequireContext` property to `true` in your Metro configuration., js engine: hermes
from storybook.
I've tested on https://github.com/dannyhw/react-native-storybook-starter and the bundle command works fine
Yes, it also works for me in a 0.71 sandbox project.
The metro and babel config files are the same, the only difference is the versions in package.json
.
I tried updating all modules one by one until I upgraded RN to 71 and then it worked.
diff --git a/package.json b/../SBsandbox/package.json
index 0b27114..4d87d4d 100644
--- a/package.json
+++ b/../SBsandbox/package.json
@@ -1,46 +1,55 @@
{
- "name": "SBsandbox71",
+ "name": "sbsandbox",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
- "lint": "eslint .",
"start": "react-native start",
"test": "jest",
+ "lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"storybook-generate": "sb-rn-get-stories"
},
"dependencies": {
- "react": "18.2.0",
- "react-native": "0.71.19"
+ "react": "18.1.0",
+ "react-native": "0.70.13"
},
"devDependencies": {
- "@babel/core": "^7.20.0",
- "@babel/preset-env": "^7.20.0",
- "@babel/runtime": "^7.20.0",
+ "@babel/core": "^7.12.9",
+ "@babel/runtime": "^7.12.5",
"@react-native-async-storage/async-storage": "^1.23.1",
"@react-native-community/datetimepicker": "^8.0.1",
- "@react-native-community/eslint-config": "^3.2.0",
+ "@react-native-community/eslint-config": "^2.0.0",
"@react-native-community/slider": "^4.5.2",
"@storybook/addon-ondevice-actions": "^7.6.18",
"@storybook/addon-ondevice-controls": "^7.6.18",
"@storybook/react-native": "^7.6.18",
"@tsconfig/react-native": "^2.0.2",
- "@types/jest": "^29.2.1",
- "@types/react": "^18.0.24",
+ "@types/jest": "^26.0.23",
+ "@types/react": "^18.0.21",
+ "@types/react-native": "^0.70.6",
"@types/react-test-renderer": "^18.0.0",
- "babel-jest": "^29.2.1",
+ "@typescript-eslint/eslint-plugin": "^5.37.0",
+ "@typescript-eslint/parser": "^5.37.0",
+ "babel-jest": "^26.6.3",
"babel-loader": "^8.3.0",
- "eslint": "^8.19.0",
- "jest": "^29.2.1",
- "metro-react-native-babel-preset": "0.73.10",
- "prettier": "^2.4.1",
- "react-dom": "18.2.0",
+ "eslint": "^7.32.0",
+ "jest": "^26.6.3",
+ "metro-react-native-babel-preset": "0.72.3",
+ "react-dom": "18.1.0",
"react-native-safe-area-context": "^4.10.1",
- "react-test-renderer": "18.2.0",
- "typescript": "4.8.4"
+ "react-test-renderer": "18.1.0",
+ "typescript": "^4.8.3"
},
"jest": {
- "preset": "react-native"
+ "preset": "react-native",
+ "moduleFileExtensions": [
+ "ts",
+ "tsx",
+ "js",
+ "jsx",
+ "json",
+ "node"
+ ]
}
}
from storybook.
Other than upgrading to 71 im not really sure. It does look like require context was already around on .70 after all.
One thing is that after trying a change to babel or metro make sure to clear cache because the cache sticks around.
You could try the setup with v6.5 of storybook.
from storybook.
Thanks for all your responses.
We're planning to upgrade RN version later this year. But I don't believe that SB v7.6.x is completely incompatible with RN 0.70.x - after all, everything works great, except from the minified bundling.
It seems to me that something's going wrong when bundling the preview-api
module, since the @storybook/preview-api/dist/index.js at 3279:39
where it reports the error is already minified when I open it. Also, the file on my disk does only contain 90 lines of code, but it reports the error at line 3279.
How can that be? And could I try to replace the preview-api
module with a version that's not minified? Where do I get that?
from storybook.
You could try using resolutions to get a specific version. If you go to npm you can see the version history of the package and try a few different ones. Probably it relates to how bundling was changed for that package. You can try forcing usage of the .mjs export though i tried and seemed to get the same issue.
from storybook.
Related Issues (20)
- [Bug]: Backgrounds no longer working with Angular and MDX HOT 1
- [Bug]: Cleanup logs during storybook init
- [Bug]: Angular 18 Library: Missing documentations generated by compodoc within a Angular Library project setup HOT 1
- [Bug]: Component does not lose focus under specific circumstances (vuetify)
- [Bug]: Storybook builds twice on launch HOT 13
- [Bug]: Tailwind CSS Styles Not Applying in Next.js Application
- Make chromatic (firefox) repro for user event issues
- [Bug]: Angular outputPath object not supported (TypeError [ERR_INVALID_ARG_TYPE]: The "paths[1]" argument must be of type string.)
- [Bug]: Storybook installs, dies. HOT 2
- [Bug]: Support bun as a package manager HOT 4
- [Tracking]: Onboarding V2
- [Documentation]: Vite's `build` options are silently ignored HOT 1
- [Bug]: `BrandImage` resizes itself in dark theme when resizing sidebar
- Upgrade tsup to 8 HOT 1
- [Documentation]: Add documentation for manual storybook setup without `npx storybook init` HOT 2
- [Bug]: infinite paths on Add a new story: ENAMETOOLONG. Function unavailable HOT 5
- [Bug]: `process.env` is undefined (8.1.7) HOT 1
- [Bug]: Getting signal SIGSEGV when building Next.js with Nx
- [Bug]: I'll guide you through troubleshooting the issue with installing Storybook. HOT 8
- [Bug]: After pressing the "Reset" button, the object editor adds new object properties - ones that would give compilation errors when trying to change them using TS code
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from storybook.