react-primitives is not transpiling when bundling for react-native production
See original GitHub issueIn my react-native project
node ./node_modules/react-native/local-cli/cli.js bundle --entry-file index.ios.js --platform ios --dev false --reset-cache --bundle-output /tmp/main.jsbundle --assets-dest /tmp/
**TypeError: /Users/peterp/Personal/xxx/node_modules/react-primitives/lib/modules/Platform.js: Property left of AssignmentExpression expected node to be of a type ["LVal"] but instead got "StringLiteral"**
transform[stderr]: at Object.validate (/Users/peterp/Personal/xxx/node_modules/babel-types/lib/definitions/index.js:109:13)
transform[stderr]: at Object.validate (/Users/peterp/Personal/xxx/node_modules/babel-types/lib/index.js:505:9)
transform[stderr]: at NodePath._replaceWith (/Users/peterp/Personal/xxx/node_modules/babel-traverse/lib/path/replacement.js:176:7)
transform[stderr]: at NodePath.replaceWith (/Users/peterp/Personal/xxx/node_modules/babel-traverse/lib/path/replacement.js:160:8)
transform[stderr]: at PluginPass.MemberExpression (/Users/peterp/Personal/xxx/node_modules/metro-bundler/build/JSTransformer/worker/inline.js:126:14)
I’ve narrowed it down the assignment here: https://github.com/lelandrichardson/react-primitives/blob/master/src/modules/Platform.js#L13
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:13 (3 by maintainers)
Top Results From Across the Web
Object Dot notation doesn't transpile when bundling ... - GitHub
When bundling for production I'm getting an error when using dot notation over bracket notation whilst mutating an object:.
Read more >Drastically Faster Bundling in React Native | by Evan Bacon
In Expo CLI, we configure Metro to transpile our untransformed Node modules with Sucrase, resulting in substantially faster React Native ...
Read more >Tree Shaking React Native Apps - Klarna Engineering
It all comes down to ensuring that you don't transpile ES modules to CommonJS before Webpack bundles all modules. If you're using the...
Read more >Why can't React Native (RN) convert the main.bundle.js to ...
I was wondering why do we need the RN Bridge in the React Native engine which connects the Javascript VM (JavascriptCore) with the...
Read more >Vite 3.0 vs. Create React App: Comparison and migration guide
Learn how to build React applications with Vite and how to migrate from Create React App to Vite. Compare the core concepts of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Note, the string accessor fix works for me when applied to
lib/modules/Platform.js
(notelib
, notsrc
as linked by @peterp’s original post. Theindex.js
imports directly from lib.)The issue is caused by Metro bundler inlining Platform.OS declaration during the JS transform phase, as described in these tests, so that
Platform.OS = platform.OS;
becomes"ios" = platform.OS
, which is obviously an invalid expression.If you want the change to be patched in permanently until this gets fixed, I can recommend patch-package.
Install patch-package with
npm install --dev patch-package
.Add
prepare
npm script:lib/modules/Platform.js
(and in src as well, if you want to be cool about it):patch-package
to generate patch:patches/
folder to source control.The patch should now be applied every time you
npm install
oryarn
@blargity I’ve created a very hacky release that you could test:
npm install peterp/react-primitives
.It fixes the touchable and this bundling issue. I’m using this on react-native 0.46.3. If it does work, then please do not use this long term… It’s a stopgap whilst I was trying to figure this out.
I’m fundamentally interested in sharing a design system between react-dom and react-native. It feels like we’re so close!