Skip to content
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

Pre-compile to JS from JSX #14

Closed
joeyjmorales opened this issue Apr 8, 2015 · 3 comments
Closed

Pre-compile to JS from JSX #14

joeyjmorales opened this issue Apr 8, 2015 · 3 comments

Comments

@joeyjmorales
Copy link

Hello,

When installing with npm the index.js is still in jsx format. I'd love to use it directly without having to compile it as a 3p lib within my application. Could you compile to JS as part of the build?

A bit new to react so if there is a better way I'd love to know!
Thanks.

@alex-dixon
Copy link

I was actually going to open an issue with the opposite concern. npm install gives me a js file, and I'm using gulp and Webpack. After adding the require in a JSX file and putting in the code for Dropzone component ,Webpack gave this error:

ERROR in ./~/react-dropzone/index.js
Module parse failed: /projectdir/node_modules/react-dropzone/index.js Line 73: Unexpected token <
You may need an appropriate loader to handle this file type.
| 
|     return (
|       <div className={className} style={style} onClick={this.onClick} onDragLeave={this.onDragLeave} onDragOver={this.onDragOver} onDrop={this.onDrop}>
|         <input style={{display: 'none' }} type='file' multiple ref='fileInput' onChange={this.onDrop} />
|         {this.props.children}
 @ ./client/pages/addapet/Form.jsx 14:15-40

Whether you get an error like this appears how you have React or React/Flux project set up. I fell into JSX to JS transpiling with gulp/webpack but there are other methods. Might be good to include instructions and/or accommodations as a result.

I ended up just copying the contents of index.js from the dropzone module into a new JSX file in my components folder and that seems to have worked.

@joeyjmorales
Copy link
Author

Hi @alex-dixon that is the same problem I encountered. Perhaps misleading description given the file in node_modules has a .js but the code inside is in fact jsx format.

Also using gulp (transform jsx, browserify) workflow and my work around was similar, to copy the jsx (.js) file to my local components folder and transpile it to jsx as if it were my own component so my browserify "require" paths work properly.

What would work perfectly for my gulp worfklow is:

1.) Change the existing index.js file to a index.jsx.
2.) Transpile it from to js to jsx
3.) Check in the result.

This would allow use directly from node_modules without having to jsx transpile in my build. This removed hassles in copy/pasting that is necessary to respect the "require" paths needed for browserify.

Thanks for helping clarify!

BDiehr pushed a commit to BDiehr/react-dropzone that referenced this issue Apr 24, 2015
Switched out the JSX for javascript.

See this issue: react-dropzone#14
@paramaggarwal
Copy link
Contributor

Closing as merged PR by @BDiehr.

sunil-dev7 added a commit to sunil-dev7/react-dropzone that referenced this issue Jun 11, 2021
Switched out the JSX for javascript.

See this issue: react-dropzone/react-dropzone#14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants