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

How to use JSX file name extension and not need it with import? #973

Closed
marcstober opened this issue Jul 28, 2016 · 4 comments
Closed

How to use JSX file name extension and not need it with import? #973

marcstober opened this issue Jul 28, 2016 · 4 comments
Labels

Comments

@marcstober
Copy link

https://github.com/airbnb/javascript/tree/master/react#naming says to use the JSX file name extension.

Then, a few paragraphs later, there is this code:

// good
import Footer from './Footer';

I can't get that to work. I'm finding that if I name my files with the JSX extension, I have to put the full path with extension in the import statement, and I don't want to do that:

// I don't like this
import Footer from './Footer/Footer.jsx'

// I don't like this either
import Footer from './Footer/index.jsx'

I'm pretty new to React, am I missing some babel plugin or just misunderstanding? Thanks.

@lencioni
Copy link
Contributor

You would need to set up your build tooling to resolve the extension for you. For example, if you are using webpack you want to include .jsx in the resolve.extensions option. More info: https://github.com/webpack/docs/wiki/Configuration#resolveextensions

@perrin4869
Copy link
Contributor

What if you are including it within node itself, for example, inside a test? Is there a way for node to resolve ./Footer to ./Footer.jsx?

@ljharb
Copy link
Collaborator

ljharb commented Aug 2, 2016

@perrin4869 sure, require.extensions can be modified - this is what the babel-node runner can do, or babel-runtime iirc.

@perrin4869
Copy link
Contributor

@ljharb I see, thanks! Seems to be deprecated, but if babel uses it I guess it should be ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants