React-stripe-elements: Syntax Error

Created on 20 Mar 2019  路  4Comments  路  Source: stripe/react-stripe-elements

Summary

I'm following the steps in your README to setup Stripe elements in my React app but it won't compile.

./node_modules/react-stripe-elements/src/components/Element.js
SyntaxError: <mypath>/node_modules/react-stripe-elements/src/components/Element.js: Unexpected token, expected "," (5:13)

  3 | import PropTypes from 'prop-types';
  4 | import isEqual from '../utils/isEqual';
 >5 | import {type ElementContext, elementContextTypes} from './Elements';
    |              ^
  6 | 
  7 | type Props = {
  8 |   id?: string,

Obviously I'm missing some dependency or I'm on a wrong version of React. So it seems the guide in your README is not complete with all required steps. What am I missing here?

Most helpful comment

Ah I figured it out. Stupid mistake. My IDE added an import
import injectStripe from "react-stripe-elements/src";
instead of
import injectStripe from "react-stripe-elements";

Sorry for wasting your time there.

All 4 comments

Can you share what your code looks like (specifically, where you are importing components from react-stripe-elements)? Also, does your build tool attempt to compile files within node_modules?

This looks like an issue with your build tool attempting to do so, and being unable to parse the type ElementContext import, which is for the Flow type system used internally by this project.

I've set my project up with create-react-app. I didn't change any of the advanced stuff around building. I've also not had this problem with any other library yet. But it sounds very likely that it's trying to compile the node_modules.
I will look into if that's what's going on and if so how to turn it off.

Ok! If you can create a repo with instructions on a simple reproduction, happy to help debug.

Ah I figured it out. Stupid mistake. My IDE added an import
import injectStripe from "react-stripe-elements/src";
instead of
import injectStripe from "react-stripe-elements";

Sorry for wasting your time there.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cleemputc picture cleemputc  路  5Comments

iMerica picture iMerica  路  5Comments

abachuk picture abachuk  路  3Comments

sciku1 picture sciku1  路  4Comments

michael-reeves picture michael-reeves  路  3Comments