简体   繁体   中英

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

"'import' and 'export' may appear only with '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.

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

Where 'my.esm.js' could be

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. Here's example:

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

source: eslint docs

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