Skip to content

Issue on a clean create-react-app and npm install @polkadot/api #4181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kasper-vdw opened this issue Nov 6, 2021 · 9 comments
Closed

Issue on a clean create-react-app and npm install @polkadot/api #4181

kasper-vdw opened this issue Nov 6, 2021 · 9 comments
Labels
Support Tracks issues or requests related to troubleshooting, answering questions, and user assistance.

Comments

@kasper-vdw
Copy link

kasper-vdw commented Nov 6, 2021

Hi,

After doing a clean create-react-app and npm install @polkadot/api, I get below error on npm start.

./node_modules/@polkadot/util-crypto/key/DeriveJunction.js 12:2
Module parse failed: Unexpected character '#' (12:2)
File was processed with these loaders:
./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| };
| export class DeriveJunction {
-> #chainCode = new Uint8Array(32);
| #isHard = false;
|

Am I missing a certain dependency for this repo to work out of the box?

@jacogr
Copy link
Member

jacogr commented Nov 6, 2021

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields - it is a valid JS construct.

You will need to tell Babel to treat it correctly, it has a language plugin, see https://babeljs.io/docs/en/babel-plugin-proposal-private-methods

@kasper-vdw
Copy link
Author

I'm trying to override the Babel config of create-react-app with the customize-cra plugin. I'm struggling but I should get there. Wouldn't it be good for the Polkadot dev community that this works out of the box for starting developers?

@jacogr
Copy link
Member

jacogr commented Nov 6, 2021

Sure, PRs welcome to scratch your itch.

As you can imagine, I cannot track all build tools and their inability to understand modern JS. A lot of these are just severely lacking in trying to track the world. So while I try to cater for at least the basics, it is a never-ending battle. So, if it is an issue for you, then make a PR to address.

@kasper-vdw
Copy link
Author

I understand. React is one of the most used ones though. I'll attempt to make a PR.

@jacogr
Copy link
Member

jacogr commented Nov 6, 2021

See for instance facebook/create-react-app#11339 where complaints are made around the exact same thing (browsers has support, CRA does not). The is really purely a CRA issue, nothing to do with the API, it tracks what browsers can and do support with babel/preset-env. (According to the linked issue it is solved in CRA 5.0 which is in alpha atm)

@kasper-vdw
Copy link
Author

Fair enough! Consider this issue closed. ;)

@JasonDeeper
Copy link

Vue has this error as well.

@jacogr jacogr added the Support Tracks issues or requests related to troubleshooting, answering questions, and user assistance. label Nov 8, 2021
@jacogr
Copy link
Member

jacogr commented Nov 8, 2021

Closing. Against better judgement have adjusted the build process slightly in util 7.8.2 & api 6.7.1 - this should not appear in recent vereions.

@jacogr jacogr closed this as completed Nov 8, 2021
@polkadot-js-bot
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators Nov 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Support Tracks issues or requests related to troubleshooting, answering questions, and user assistance.
Projects
None yet
Development

No branches or pull requests

4 participants