Skip to content
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

docs: common RN package issues #245

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions apps/onestack.dev/data/docs/common-issues.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,53 @@ import one from 'one/vite'

You can also try using one of the commonjs plugins, either `vite-require` or `vite-plugin-commonjs`.

### Common React Native package issues

When using bundlers like Vite, Rollup, or esbuild, developers often encounter issues with React Native and Expo packages originally designed to work only for Metro. Metro’s tolerant nature allows certain practices that other bundlers may not support, such as:

* Including Flow types in distributed `.js` files.
* Including JSX syntax in `.js` files instead of `.jsx`.
* Releasing packages as ESM-only without proper declarations in `package.json` (e.g., missing `"type": "module"`) or appropriate `.mjs` extensions.
* Omitting import path extensions in distributed ESM, which can [prevent Node.js from running those modules correctly](https://nodejs.org/docs/latest-v20.x/api/esm.html#mandatory-file-extensions), and break SSR.

These issues can break builds and require specific handling to make the packages compatible with non-Metro bundlers. Related error messages you might encounter includes:

* `The JSX syntax extension is not currently enabled.`
* `The esbuild loader for this file is currently set to "js" but it must be set to "jsx" to be able to parse JSX syntax.`
* `SWC failed to transform file` following with a syntax error parsing something like `import type`.

To workaround these issues, you can use the package patching feature of One to fix the packages that are causing problems. Here's an example:

```tsx fileName=vite.config.ts
export default {
plugins: [
one({
// ...
deps: {
'react-native-vector-icons': {
'**/*.js': [
'jsx', // Transpile JSX in .js files
'flow', // Remove flow types
],
},
},
}),
],
}
```

For more details, see the [`deps` section in Configuration](/docs/configuration#deps).

<Notice>
We encourage you to [open an issue](https://github.com/onejs/one/issues/new) on our GitHub repository if you encounter similar issues, as your feedback helps us improve One's compatibility with React Native packages.

If you've resolved an issue with a patch, we'd love for you to share your patch configuration. Alternatively, feel free to reach out, and we'll gladly assist in finding a solution to get things working.
</Notice>

<Notice>
If appropriate, it's also nice to reach out to the maintainers of those packages to help improve their compatibility with non-Metro bundlers.
</Notice>

### Application has not been registered

One calls AppRegistry.registerComponent for you to set up your React Native entry component.
Expand Down