score:4

Accepted answer

Here is how I resolved the issue.

    • Add the following content to your .babelrc file and make sure .babelrc is in the root folder
{ "presets": ["env","react"] }
    • Make sure you exclude static assets like CSS, images, SCSS, PDF, fonts, etc. Add the following to package.json as highlighted in the screenshot
"moduleNameMapper": {
  "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
    "<rootDir>/__mocks__/fileMock.js",
  "\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js"
}

Screenshot:

exclude-static-assets

score:0

If anybody comes here to figure out what is happening, I think the accepted answer is not related to the issue here.

When the file extension is .js and if you try to write JSX in that file, linter will complain if you have a correct ESlint configuration.

Instead, try to change the file extension to .jsx or .tsx (if Typescript involved).


Related Query

More Query from same tag