[英]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. 我正在尝试禁用
Parsing error: 'import' and 'export' may only appear at the top level
特定文件Parsing error: 'import' and 'export' may only appear at the top level
,但我似乎无济于事。
someScript.js 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. 注释
eslint-disable-next-line
或/* eslint-disable */
不会执行任何操作,也不会创建eslint配置或忽略文件。 Using create-react-app to build. 使用create-react-app构建。 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. 您不能使用
/* eslint-disable */
来禁用它,因为它是解析错误,即代码无效的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. 如果需要条件模块加载,则可以使用
require('./someFile')
,根据环境的不同,它可能会或可能不会起作用。
Try this: 尝试这个:
import { /* eslint-disable */
someFunction /* eslint-disable */
} from "./someFile";/* eslint-disable */
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.