babel-plugin-react-native-electron

raw JSON →
0.2.0 verified Sat Apr 25 auth: no javascript

A Babel plugin (v0.2.0, stable) that resolves imports for react-native-electron, enabling React Native components to run in Electron. It remaps react-native imports to react-native-electron and optionally transforms to CommonJS. Needed when targeting Electron with React Native codebases. Rarely updated but fills a specific niche.

error Module not found: Can't resolve 'react-native' in '...'
cause Babel is not transforming imports, so webpack tries to resolve 'react-native' directly (which fails in Electron).
fix
Ensure babel-plugin-react-native-electron is in your plugins array (e.g., .babelrc or babel.config.js) and that Babel is running on the affected files.
error SyntaxError: Unexpected token import (or require)
cause Babel is not configured to handle ES module syntax for the plugin target.
fix
Add @babel/preset-env or @babel/plugin-transform-modules-commonjs to your Babel config.
error window is not defined (ReferenceError)
cause Electron's renderer process does not have a DOM window during initialization if nodeIntegration is false or contextIsolation is true.
fix
Set nodeIntegration: true and contextIsolation: false in the BrowserWindow options, or use preload scripts.
gotcha The plugin requires react-native-electron to be installed separately.
fix Run 'yarn add react-native-electron' or 'npm install react-native-electron'.
gotcha The plugin only transforms imports/exports; it does not polyfill Node.js APIs (e.g., fs, path). You may need additional Webpack config or electron-renderer-target.
fix Configure Webpack target: 'electron-renderer' and add node: { __dirname: false, __filename: false }.
gotcha The plugin does not handle CSS or asset imports; those must be processed separately (e.g., with Webpack).
fix Add a CSS loader and file-loader/asset modules to your Webpack config.
gotcha No known breaking changes or deprecations.
fix N/A
npm install babel-plugin-react-native-electron
yarn add babel-plugin-react-native-electron
pnpm add babel-plugin-react-native-electron

Add the plugin to your Babel config with the commonjs option.

{
  "plugins": [
    ["react-native-electron", { "commonjs": true }]
  ]
}