ds300 / react-native-typescript-transformer

Seamlessly use TypeScript with React Native
MIT License
657 stars 50 forks source link

"Unexpected token '.'" error when using whatwg-url #60

Closed Fitzpasd closed 6 years ago

Fitzpasd commented 6 years ago

When using the popular library whatwg-url, I get this unhelpful error:

screenshot-1524677787605

I narrowed it down to this library by commenting out code locally. In the end, this is the cause:

import { URL } from "whatwg-url";
...
const url = new URL("https://github.com");

Without that code, no error occurs. It's also interesting to note that if you're debugging via Chrome, this error doesn't occur.

luisnaranjo733 commented 6 years ago

I'm also hitting this

ds300 commented 6 years ago

Hi! :wave: Thanks for the report.

Seems to be an issue with whatwg-url + JavaScriptCore (the JS engine that react-native uses when running on the client, when debugging via chrome it uses v8 and communicates over the native bridge via websockets)

I tried to reproduce this without setting up typescript. It still errored just by importing whatwg-url, but the message was different: new.target can't come after a prefix operator

I found this related discussion: https://github.com/jsdom/whatwg-url/issues/108

Seems like whatwg-url only supports node at the moment so you'd probably be best off trying a different lib.

Fitzpasd commented 6 years ago

Thanks for the extra info! I'll find an alternative lib :)

ds300 commented 6 years ago

Another link I found seems to imply that the JSC bug was fixed late last year but I guess RN hasn't caught up: https://bugs.webkit.org/show_bug.cgi?id=157970#c17