React Noob here.
I have been stuck on this for a little while.
I have tried to add a module into a project I'm making, but found the same problem occurs when I run it with a new create-react-app.
I believe it is related to babel/JSX, because if I put the imported modules src into a fresh project or just into the src of the existing one it seems to compile fine, just not as an import.
1) set up new react app:
npx create-react-app test-project
cd test-project
2) install package:
npm install --save react-collision-provider
3) Add an import to the App.js
+ import { collisionProviderFactory } from 'react-collision-provider';
4) start project
npm start
Error:
./node_modules/react-collision-provider/src/components/collisionProviderFactory.js
SyntaxError: /Users/XXXXXXX/Documents/TestProjects/test-project/node_modules/react-collision-provider/src/components/collisionProviderFactory.js: Unexpected token (37:14)
35 | render() {
36 | const Component = this.props.component;
> 37 | return (<Component
| ^
38 | onCollision={this.onCollision}
39 | updatePosition={this.updatePosition}
40 | {...this.props}
I have tried to mess around with different babel settings and ejecting the project but no luck. I heard CRA doesn't transpile node_modules only src, but not sure how to compile the JSX in advanced in the node_modules?
Thanks.