简体   繁体   English

如何告诉 eslint:禁用下一行“'import'和'export'可能只与'sourceType:module'一起出现”

[英]How to tell eslint to: disable next line "'import' and 'export' may appear only with 'sourceType: module'"

How to tell eslint to: disable next line for如何告诉 eslint:禁用下一行

"'import' and 'export' may appear only with 'sourceType: module'" "'import' 和 'export' 只能与 'sourceType: module' 一起出现"

Without configuration , it has to be inline .没有配置它必须是内联的

The following doesn't seem to be working以下似乎不起作用

/* eslint-disable */
// eslint-disable-next-line

Why:为什么:

Let's say you are writing a test inside a NON module project, and you want to prove you can or cannot dynamically import an ESM module.假设您正在非模块项目中编写测试,并且您想证明您可以或不能动态导入 ESM 模块。

describe('my test', it("doesn't work", ()=> require('./my.esm.js'))

Where 'my.esm.js' could be 'my.esm.js' 可能在哪里

export function noop {}

...or whatever ...管他呢

But the main project, nor the tests are module based.但是主要项目和测试都是基于模块的。

You can try to add "sourceType": "module" to your eslint config file.您可以尝试将"sourceType": "module"到您的 eslint 配置文件中。 Here's example:下面是例子:

{
"parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
        "jsx": true
    }
},
"rules": {
    "semi": "error"
}
}

source: eslint docs来源: eslint 文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 create-react-app eslint 错误“解析错误:‘import’和‘export’可能只出现在‘sourceType:module’中” - create-react-app eslint error "Parsing error: 'import' and 'export' may appear only with 'sourceType: module'" cypress + lerna: ParseError: 'import' 和 'export' 可能只出现在 'sourceType: module' 中 - cypress + lerna: ParseError: 'import' and 'export' may appear only with 'sourceType: module' Cypress ParseError: 'import' 和 'export' 可能只出现在 'sourceType: module' - Cypress ParseError: 'import' and 'export' may appear only with 'sourceType: module' 'import' 和 'export' 只能与 'sourceType: "module"' 一起出现 (16:0) - 'import' and 'export' may appear only with 'sourceType: "module"' (16:0) SyntaxError: 'import' 和 'export' 可能只与 'sourceType: module' 一起出现 - Gulp - SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' - Gulp ParseError: 'import' 和 'export' 可能只出现在 'sourceType: module', browserify - ParseError: 'import' and 'export' may appear only with 'sourceType: module', browserify NPM + Browserify 错误:ParseError: 'import' 和 'export' 可能只出现在 'sourceType: module' 中 - NPM + Browserify error: ParseError: 'import' and 'export' may appear only with 'sourceType: module' 开玩笑的返回错误:SyntaxError:“导入”和“导出”可能仅与“ sourceType:“模块””一起出现(21:0) - jest return ERROR: SyntaxError: 'import' and 'export' may appear only with 'sourceType: “module”' (21:0) Babel 7 不转译 node_modules 中的依赖项:'import' 和 'export' 可能只与 'sourceType: module' 一起出现 - Babel 7 not transpiling dependencies in node_modules: 'import' and 'export' may appear only with 'sourceType: module' Browserify Rails错误-ParseError:“导入”和“导出”可能仅与“ sourceType:模块”一起出现 - Browserify Rails Error - ParseError: 'import' and 'export' may appear only with 'sourceType: module'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM