bitauth / libauth

An ultra-lightweight, zero-dependency TypeScript library for Bitcoin Cash, Bitcoin, and Bitauth applications.

Home Page:https://libauth.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot use with Create React App

OR13 opened this issue · comments

Create a new React App:

npx create-react-app debug-libauth
cd debug-libauth
npm i @bitauth/libauth --save

Add to App.js

import * as bitcoin from '@bitauth/libauth'
console.log(bitcoin)

Run the app

npm run start

Observe the error

./node_modules/@bitauth/libauth/build/module/lib/template/compiler.js 112:37
Module parse failed: Unexpected token (112:37)
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.
|   }), {});
|   const entityOwnership = Object.entries(template.entities).reduce((all, [entityId, entity]) => ({ ...all,
>     ...Object.keys(entity.variables ?? {}).reduce((entityVariables, variableId) => ({ ...entityVariables,
|       [variableId]: entityId
|     }), {})

Version info:

 "@bitauth/libauth": "^1.15.3",
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-scripts": "3.4.1"

Pretty sure is this CRA / Babels fault and not this library... this worked a few weeks ago.

As expected... this error goes away when using create react app with typescript...

create-react-app debug-bitcoin-ts-typescript --template typescript

Sigh...

hacking on the files... it looks like ?? and optional chaining are in javascript source files... https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#optional-chaining
https://medium.com/@rd1982rd/double-question-marks-over-typescript-3-7-nullish-coalescing-40cbe0404c45

I would not expect to see these in a vanilla javascript module.

However, this appears to indicate that they should be supported: facebook/create-react-app#7438

It would appear this is an issue with this module after all...

I made a test module

const derp  = null;
module.exports = {
    data: derp ?? {'foo': derp?.bar}
}

and I can import it just fine without the loader exploding....

import * as foo from './test-module'
console.log(foo);
console.log(require('./test-module'))

Hi @OR13, sorry I missed responding to this earlier! Did you get this issue figured out? If not, could you push an example of a breaking repo to GitHub? (I'm afraid I can't reproduce locally – I suspect that might mean you're getting a different version of some dependencies from your local npm or yarn cache. You could try to clear that too.)

For a working example of a Create React App which uses Libauth, check out Bitauth IDE on GitHub.

Thanks! I ended up switching to another implementation, if you can't repro with the latest versions, its probably been fixed and you should feel free to close this issue.

I just retested this, and it's still happening.

https://github.com/OR13/bitauth-cra

npm i 
npm run start

@OR13 thanks for bringing this back up! Right now it seems to be a bug in Create React App – I added a comment to an existing issue here: facebook/create-react-app#9468

I think it may be a regression in CRA, since bitauth-ide is working as expected (react-scripts at v3.4.1).

This has been fixed by #62. 🎉
Thanks @rkalis!