nervosnetwork / polyjuice-provider

Godwoken-Polyjuice compatible providers for ethereum library
https://www.npmjs.com/org/polyjuice-provider
8 stars 13 forks source link

Create React App incompatibility #61

Closed e00dan closed 2 years ago

e00dan commented 2 years ago

Create React App complains if you try to use @polyjuice-provider/base:

./node_modules/@polyjuice-provider/base/lib/util.js 436:25
Module parse failed: Unexpected token (436:25)
File was processed with these loaders:
 * ./node_modules/react-scripts/node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|   constructor(host, option) {
|     const callServer = function (request, callback) {
>       const opt = option?.request_option || {
|         method: "POST",
|         body: request,

image

Another problematic place is:

Failed to compile.

./node_modules/@polyjuice-provider/base/lib/util.js 453:61
Module parse failed: Unexpected token (453:61)
File was processed with these loaders:
 * ./node_modules/react-scripts/node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| 
|     this.client = jaysonBrowserClient(callServer);
>     this.godwokenUtils = new godwoken_1.GodwokenUtils(option?.godwoken?.rollup_type_hash);
|     this.eth_account_lock = option?.godwoken?.eth_account_lock;
|     this.rollup_type_hash = option?.godwoken?.rollup_type_hash;

This is problematic because many newcomers to Nervos can't use Create React App out of the box if they want to use @polyjuice-provider/base (or packages that depend on it - such as nervos-godwoken-integration). They would have to eject and use custom config.

Eg. that's why in nervos-evm-starter repo I have to use config-overrides.js: https://github.com/Kuzirashi/nervos-evm-starter/blob/master/config-overrides.js with following code:

module.exports = function override(config) {
    config.module.rules[1].oneOf[3].options.plugins = [
        "@babel/plugin-proposal-optional-chaining"
    ];

    return config;
}