How to enable the use of es6 imports when compiling Expo app with Electron

Hello! I’m new to using Expo for desktop (using Electron).

The problem that I have is that it doesn’t seem to support es6 imports. I’m compiling the app with the following command:

yarn electron-webpack && yarn electron-builder --dir -c.compression=store -c.mac.identity=null

But when I launch the compiled app here’s what I get:

I have set up Expo for desktop using the instructions here: https://github.com/expo/expo/blob/master/docs/pages/versions/unversioned/guides/using-electron.md

My babel.config.js includes babel-preset-expo which I assume enables me to use the es6 import keyword:

module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo', 'module:metro-react-native-babel-preset', 'module:react-native-dotenv'], // update this to make dot-env work
  };
};

I tried using require() in the node_modules/expo/AppEntry.js file instead:

const registerRootComponent = require('expo').registerRootComponent;
const activateKeepAwake = require('expo-keep-awake').activateKeepAwake;

const App = require('../../App');

if (__DEV__) {
  activateKeepAwake();
}

registerRootComponent(App);

But this just returned the same error on a different file.

I’ll continue trying to figure this out, but any guidance would be appreciated. Thank you!

Did you ever get anywhere with this error? I’m having the same issue and have tried a number of fixes but none seem to work (javascript - SyntaxError: Cannot use import statement outside a module - Stack Overflow)

i was also experiencing this error. it seems there is an open issue here [electron] Can't run built application · Issue #8 · expo/expo-electron-adapter · GitHub

i tried adding the following build config and it fixed the issue for me [electron] Can't run built application · Issue #8 · expo/expo-electron-adapter · GitHub

have a nice day!

1 Like