简体   繁体   中英

Disable eslint in creare-react-app - specific file

I'm trying to disable Parsing error: 'import' and 'export' may only appear at the top level in a specific file but nothing I do seems to work.

someScript.js

(function() {
  if (window.hasRun) {
    return true;
  }
  window.hasRun = true;

  import {
    someFunction
  } from "./someFile";
});

Commenting eslint-disable-next-line or /* eslint-disable */ doesn't do anything and neither does creating an eslint config or ignore files. Using create-react-app to build. Am I doing something wrong?

You cannot disable it with /* eslint-disable */ because it is a parsing error, that is, the code is not valid Javascript. Just as the error message suggests, import statements must be located at the top level of the program. If you need conditional module loading, you may use require('./someFile') , it might or might not work depending on your environment.

Try this:

import { /* eslint-disable */
    someFunction /* eslint-disable */
  } from "./someFile";/* eslint-disable */
});

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