Unexpected token = import/no-named-as-default eslint error

Unexpected token = import/no-named-as-default eslint error



I create an AppBar component and I want to export the component in the App component.


AppBar


App



src/components/appbar.jsx:


import React from 'react';
import PropTypes from 'prop-types';
import withStyles from '@material-ui/core/styles';
import AppBar from '@material-ui/core/AppBar';
import Toolbar from '@material-ui/core/Toolbar';
import IconButton from '@material-ui/core/IconButton';
import MenuIcon from '@material-ui/icons/Menu';
import LeftDrawer from './leftDrawer';

const styles =
root:
flexGrow: 1,
,
flex:
flexGrow: 1,
,
menuButton:
marginLeft: -12,
marginRight: 20,
,
;

class ButtonAppBar extends React.Component
state =
left: false,

toggleDrawer = (side, open) => () =>
this.setState(
[side]: open,
);
;
render()
const classes = this.props;
return (
<div className=classes.root>
<AppBar position="static">
<Toolbar>
<IconButton
className=classes.menuButton
color="inherit"
aria-label="Menu"
onClick=this.toggleDrawer('left', true)
>
<MenuIcon />
</IconButton>
<LeftDrawer
open=this.state.left
toggleDrawer=this.toggleDrawer
/>
</Toolbar>
</AppBar>
</div>
);
;


ButtonAppBar.propTypes =
classes: PropTypes.object.isRequired,
;

export default withStyles(styles)(ButtonAppBar);



src/app.jsx:


import React from 'react';
import ButtonAppBar from './components/appBar';


const App = () => (
<div>
<ButtonAppBar />
</div>
);

export default App;



.estlinrc.json:



"extends": [
"airbnb", "prettier"
],
"env":
"browser": true
,
"rules":
"react/forbid-prop-types": "off"
,
"settings":
"import/extensions": [".jsx", ".js"],
"import/resolver":
"webpack":
"config": "webpack.config.js"






.babelrc.json:



"presets": [
"env",
"react"
],
"plugins": ["transform-class-properties"]



package.json:


"devDependencies":
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"eslint": "^5.4.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-prettier": "^3.0.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.1",
"eslint-plugin-react": "^7.11.1",
"prettier": "^1.14.2",
"webpack": "^4.17.0",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.5"





When I run the instruction:


./node_modules/.bin/eslint --ext .js,.jsx ./



I got this error:


Parse errors in imported module './components/appBar': Unexpected token = (24:9) import/no-named-as-default



I found a similar question here How do I resolve eslint import/no-named-as-default and in the accepted answer it disable the rule import/no-named-as-default.
Is there any solution to keep this rule and update the code to not get this error?


import/no-named-as-default




1 Answer
1



Seems you're either not using babel-eslint as the parser, missing the babel-transform-class-properties plugin in your setup, or eslint is not configured to use it, or it's an older version of eslint.



Hope one of these is the culprit!





I added .babelrc.json and the package.json to my question
– para 008
Aug 22 at 18:12


.babelrc.json


package.json





Cool. Try installing babel-eslint and using "parser": "babel-eslint" in your eslintrc file!
– Dan
Aug 22 at 18:16


babel-eslint


"parser": "babel-eslint"





It works, thank you.
– para 008
Aug 22 at 18:59






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)