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.

Unexpected use of file extension "jsx" for "./components/App.jsx" (import/extensions)

See original GitHub issue

Unable to use .jsx extension using the airbnb ESLint config

index.jsx

import React from 'react';
import App from './components/App.jsx'; <<<<<<<<< Unexpected use of file extension "jsx"...

ReactDOM.render(
  <App />,
  document.getElementById('root'),
);

.eslintrc

{
  "extends": "airbnb",
  "env":{
    "browser": true
  },
  "plugins": [
    "react",
    "jsx-a11y",
    "import"
  ],
  "rules": {
    "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
  }
}

Dependencies

  • “eslint”: “^4.10.0”,
  • “eslint-config-airbnb”: “^16.1.0”,
  • “eslint-plugin-import”: “^2.8.0”,
  • “eslint-plugin-jsx-a11y”: “^6.0.2”,
  • “eslint-plugin-react”: “^7.4.0”,

Unsuccessful Implementations/Examples

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

13reactions
ljharbcommented, Nov 3, 2017

You’re not supposed to use the extension there. The best practice for file extensions on imported code is to omit them, which is why our config requires that as well.

10reactions
wsfullercommented, Nov 4, 2017

@ljharb Sorry the previous question didn’t correctly state my issue. The omitting of file extensions in import statements is fine, the actual problem I was having was resolving .jsx with Webpack without setting up a resolve object in my webpack.config.

In reading the documentation I was trying to find something like:

"In creating imports omit your file extensions. In the case you are using Webpack you can resolve paths using Webpack Resolve in your webpack.config

Ex.

module.exports = {
...
  resolve: {extensions: ['.js','.jsx']}
...
}

In doing that, the issue was resolved. I’m hoping that is the correct way to get things setup properly. Just having something to point me in the right direction would’ve been really helpful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React ESLint Config "Unexpected file extension JSX"
Removed extension on import statement: import App from './components/App';. Which lead to unable to resolve error.
Read more >
I had to add this to .eslintrc.js "import/extensions": [ "error...
Discussion on: How to setup a React. ... You should also add the other line jsx-filename-extension and then it also needs import resolver....
Read more >
React ESLint Config “Unexpected file extension JSX” - iTecNote
Running Airbnb's Eslint Config and running into an issue using the .jsx extension. index.jsx import React from 'react'; import ReactDOM from 'react-dom'; ...
Read more >
Curso Profesional de React Hooks - Platzi
Alguna sugerencia este error me lo envia el eslint Unexpected use of file extension “jsx” for “./components/App.jsx” import/extensions. Víctor VíctorMoya07.
Read more >
https://unpkg.com/react-beautiful-dnd@2.2.4/.eslintrc
... to add file extensions for the following extensions "import/extensions": ... /eslint-plugin-react/blob/master/docs/rules/jsx-sort-props.md // JSX props ...
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