ES6 not supported after electronic packaging

I use various ES6 syntax (e.g. import , etc.) and React code ( JSX ) in Electron . During development, I use the electron-prebuilt-compile package (as a dev dependency) to support these new features, and it works fine, without errors.

But after packing my application using electron-packager and running the redistributable application file, I experience unsupported ES6-related errors such as

 Unexpected token import 

This is how I run the electronic wrapper command (pay attention to the flags of the platform and architecture):

 electron-packager . MyCoolApp --platform=linux --arch=x64 

Any reason why the packaged / distributed version of my application does not support ES6 / React features?

+5
source share
2 answers

solvable.

It turns out that devDependencies are omitted by default by default, which means that the electron-prebuild-compile package "left the game" for the packaged application, and without it ES6 cannot be compiled. Therefore, in order to deactivate this default behavior, I had to call the packager command with the --no-prune flag so that devDependencies would remain without deletion:

 electron-packager . MyCoolApp --platform=linux --arch=x64 --no-prune 

In addition, I had to introduce a new script (let him call it: es6-init.js ) to initialize the main script application in order to β€œcompile” the code before rendering (it should be used as the main script entry point of your application):

 var appRoot = path.join(__dirname, '..'); require('electron-compile').init(appRoot, require.resolve('./main')); 

Literature:

+2
source

Nodejs (and Electron along with it) does not support import and export . You will need to use require();

0
source

Source: https://habr.com/ru/post/1276159/


All Articles