question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support index.jsx entry file

See original GitHub issue

While I understand that the jsx extension is supported but not recommended, I was surprised that my index.jsx file isn’t being recognized after renaming it to pass eslint-config-airbnb’s jsx extension requirement.

Is this a bug report?

Sort of, I was surprised this wasn’t supported but it may be an intentionally missing feature.

Which terms did you search for in User Guide?

index.js, it’s clear that it’s currently expected for the filename to be an exact match.

Steps to Reproduce

  1. Rename index.js to index.jsx
  2. npm start

Expected Behavior

App runs normally, treating index.jsx as the same as index.js when it’s not present.

Actual Behavior

> react-scripts start

Could not find a required file.
  Name: index.js
  Searched in: /Users/nick/Repos/password-entropy/src
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ start: `react-scripts start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:12
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

9reactions
nickmccurdycommented, Sep 20, 2017

@torabian This may be simple for just create-react-app alone, but it doesn’t play well with developer tools. It took me at least an hour or two to get this working properly, and this affects a lot of people.

Here’s what this change involves for me:

  1. Configure all Emacs modes to find JSX syntax in JS extension files. This is usually as simple as updating auto-mode-alist, but for packages like web-mode that handle multiple syntaxes, this quickly becomes complicated and difficult to debug.
  2. Configure linter to allow JSX in JS files. I use eslint-config-airbnb, so I either have to violate its requirement or configure the rule to be disabled for this file. Either way, I should not need to violate linter or style guide rules because of technology choices.
  3. If a project has any style guide documentation, you would have to document that index.jsx isn’t allowed and index.js has to be used instead, causing potential confusion and additional style guide violations.
7reactions
nickmccurdycommented, Sep 20, 2017

That’s a great workaround, but I’m concerned about it creating confusion for contributors. If I haven’t used create-react-app before and I only had experience with React and Webpack, I wouldn’t be sure if I should be opening index.js or index.jsx to change functionality, and it wouldn’t be clear at first glance why both need to exist.

Read more comments on GitHub >

github_iconTop Results From Across the Web

webpack can't find module if file named jsx - Stack Overflow
Webpack doesn't know to resolve .jsx files implicitly. You can specify a file extension in your app ( import App from '.
Read more >
Introducing JSX - React
It is called JSX, and it is a syntax extension to JavaScript. We recommend using it with React to describe what the UI...
Read more >
How to Structure a React Project? - ReactJS News
The index.js files provide us neat entry points to the files so they are easy to consume from elsewhere. Each component is a...
Read more >
Say “Hello World!” with the Create React App - Sweetcode.io
/src/index.js is the entry point of the project that React will be looking into before any other files. (Keep in mind that these...
Read more >
API - ESBuild
There you can use regular JavaScript syntax to eliminate cross-platform differences. #Entry points. Supported by: Build. This is an array of files that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found