简体   繁体   中英

eslint: Parsing error: Unexpected token during import

In a ReactJS app, I have an index.js file with the following imports:

export MainContainer from './Main/MainContainer';
export AboutContainer from './About/AboutContainer';

When I run ESLINT, I get the following error:

error  Parsing error: Unexpected token MainContainer

The error message is not referencing any of the eslint rules set up in .eslintrc.json. The app runs fine in Chrome with no console errors. Why is eslint throwing the error?

You have export instead of import while trying to import. Try:

import MainContainer from './Main/MainContainer';
import AboutContainer from './About/AboutContainer';

;)

If you're trying to re-export components, you'll need the braces:

export { MainContainer } from './Main/MainContainer';
export { AboutContainer } from './About/AboutContainer';

If it's re-exporting default exports:

export { default as MainContainer } from './Main/MainContainer';
export { default as AboutContainer } from './About/AboutContainer';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM