{"id":19136,"library":"babel-plugin-react-native-electron","title":"babel-plugin-react-native-electron","description":"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.","status":"active","version":"0.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/mybigday/babel-plugin-react-native-electron","tags":["javascript"],"install":[{"cmd":"npm install babel-plugin-react-native-electron","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-react-native-electron","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-react-native-electron","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Babel plugins are CommonJS modules; they cannot be imported via ESM in .babelrc.","wrong":"import plugin from 'babel-plugin-react-native-electron'","symbol":"default","correct":"module.exports = function(babel) { ... }"},{"note":"Without the options array, the plugin may not be configured correctly.","wrong":"{\"plugins\": [\"react-native-electron\"]}","symbol":"config in .babelrc","correct":"{\"plugins\": [[\"react-native-electron\", { commonjs: true }]]}"},{"note":"Use the full string (with babel-plugin- prefix) or the shorthand 'react-native-electron'.","wrong":"module.exports = { plugins: ['babel-plugin-react-native-electron'] }","symbol":"require in babel.config.js","correct":"module.exports = { plugins: [['babel-plugin-react-native-electron', { commonjs: true }]] }"}],"quickstart":{"code":"{\n  \"plugins\": [\n    [\"react-native-electron\", { \"commonjs\": true }]\n  ]\n}","lang":"javascript","description":"Add the plugin to your Babel config with the commonjs option."},"warnings":[{"fix":"Run 'yarn add react-native-electron' or 'npm install react-native-electron'.","message":"The plugin requires react-native-electron to be installed separately.","severity":"gotcha","affected_versions":"all"},{"fix":"Configure Webpack target: 'electron-renderer' and add node: { __dirname: false, __filename: false }.","message":"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.","severity":"gotcha","affected_versions":"all"},{"fix":"Add a CSS loader and file-loader/asset modules to your Webpack config.","message":"The plugin does not handle CSS or asset imports; those must be processed separately (e.g., with Webpack).","severity":"gotcha","affected_versions":"all"},{"fix":"N/A","message":"No known breaking changes or deprecations.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"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.","cause":"Babel is not transforming imports, so webpack tries to resolve 'react-native' directly (which fails in Electron).","error":"Module not found: Can't resolve 'react-native' in '...'"},{"fix":"Add @babel/preset-env or @babel/plugin-transform-modules-commonjs to your Babel config.","cause":"Babel is not configured to handle ES module syntax for the plugin target.","error":"SyntaxError: Unexpected token import (or require)"},{"fix":"Set nodeIntegration: true and contextIsolation: false in the BrowserWindow options, or use preload scripts.","cause":"Electron's renderer process does not have a DOM window during initialization if nodeIntegration is false or contextIsolation is true.","error":"window is not defined (ReferenceError)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}