expo / expo-electron-adapter

This package wraps `electron-webpack` and adds support for Expo web and other universal React packages.
MIT License
29 stars 11 forks source link

[electron] Can't use electron out-of-the-box with sdk 36. #9

Open yungkittty opened 4 years ago

yungkittty commented 4 years ago

Description

I'm trying to setup expo with electron (SDK 36).

To do so, I've followed this guide.

Finally, I've tried to run yarn expo-electron start.

Expected Behavior

It should start the electron app using the AppEntry.js (main field from package.json) or whatever pre-configured (index||app).(js||ts) from expo. This would ensure all the configuration of expo for web apps is also applied to electron and it would keep a universal entry point (if none special configuration).

Observed Behavior

┏ Renderer -------------------

  Error: Cannot find entry file index.ts (or main.ts, or app.ts, or index.js, or main.js, or app.js)
      at computeEntryFile (/home/x/Clones/happew-boilerplate/node_modules/electron-webpack/src/main.ts:389:11)
      at WebpackConfigurator.configure (/home/x/Clones/happew-boilerplate/node_modules/electron-webpack/src/main.ts:222:29)
      at configure (/home/x/Clones/happew-boilerplate/node_modules/electron-webpack/src/main.ts:376:10)

┗ ----------------------------

I've looked-up the configuration of electron-webpack and it's this function that throw this error. From all the docs and examples provided by expo none talks about declarating a (index||app).(js||ts) file.

Environment

Expo CLI 3.11.3 environment info:
    System:
      OS: Linux 4.15 elementary OS 5.1 Hera
      Shell: 4.4.20 - /bin/bash
    Binaries:
      Node: 13.5.0 - ~/.nvm/versions/node/v13.5.0/bin/node
      Yarn: 1.21.1 - ~/.nvm/versions/node/v13.5.0/bin/yarn
      npm: 6.13.4 - ~/.nvm/versions/node/v13.5.0/bin/npm
    npmPackages:
      @types/react: ~16.9.0 => 16.9.17 
      @types/react-native: ~0.60.23 => 0.60.25 
      expo: ~36.0.0 => 36.0.2 
      react: ~16.9.0 => 16.9.0 
      react-native: https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz => 0.61.4 
    npmGlobalPackages:
      expo-cli: 3.11.3

Reproducible Demo

I've this error with this repository (expo/examples) which use the sdk 35.

lukasluecke commented 4 years ago

I had the same issue. Creating an empty index.js in the main directory skips the error, the renderer then loads the custom entry point successfully.

Not sure if that's something that should be fixed by the expo-electron setup or in electron-webpack. Maybe just add it to the guide for now?

juuisle commented 4 years ago

I had the same issue.

liquid8d commented 4 years ago

Had the same issue as well building on Linux, adding empty index.js worked, thanks!

FWIW, the Windows and Mac versions built fine with the same package.json referencing AppEntry.js

Ngomana commented 3 years ago

Where do i add the index.js file Screenshot from 2021-01-03 19-33-55

fangpenlin commented 2 years ago

I encountered the same problem and I dug a bit to understand why it works on Windows / Mac but not Linux. So basically,

https://github.com/electron-userland/electron-webpack/blob/ca18b60daa172c8f0249f9bf4e89a2f76a1cbe44/packages/electron-webpack/src/main.ts#L381-L385

the electron-webpack main is trying to find index, main and app with any one of suffixes among ts, js, tsx and jsx. For Expo app, you got App.tsx in the renderer source folder ./ defined here

https://github.com/expo/expo-electron-adapter/blob/b9de1864183116d3332d651cdfa9575f54441585/src/Config.ts#L75

Under Windows or MacOS, as if the filesystem is using case insensitive filename filesystem, the computeEntryFile is gonna find App.tsx regardless it's not app.tsx. But for Linux, usually case sensitive filename filesystem is used, as a result, it cannot find the entry point for index file.

A simple solution by adding an empty index.js in renderer source folder could work, and it should be filtered out by this adapter here:

https://github.com/expo/expo-electron-adapter/blob/b9de1864183116d3332d651cdfa9575f54441585/src/Webpack.ts#L80-L85

Simbaclaws commented 2 years ago

Can't yarn expo-electron be altered to create a empty index.js file if it doesn't yet exist?

It really doesn't have to be that hard to implement a solution to this just to have support for linux out of the box.... It's embarrassingly easy to add to this project no?

ollyde commented 1 year ago

@Simbaclaws doesn't work for me, loads of issues when adding it to a blank expo project.