简体   繁体   中英

Converting eslint config from json to JavaScript throws error when exporting config

I am trying to convert my eslint config from json to JavaScript.

After exporting a config object from .eslintrc.js like it sys in the docs :

JavaScript - use .eslintrc.js and export an object containing your configuration.

I get the error:

(function (exports, require, module, __filename, __dirname) { export default {
                                                              ^^^^^^

SyntaxError: Unexpected token export
    at new Script (vm.js:83:7)

This is the first couple of lines of my config:

export default {
    env: {
        browser: true,

How can I fix the error?

Update

I have named the object and exported the const but get this error:

const config = {
    env: {
export default config;
^^^^^^

SyntaxError: Unexpected token export
    at new Script (vm.js:83:7)

you should use module.exports like this:

module.exports = {
  putYour: "config here"
};

thats all that you need

This is what I have in my .eslintrc.js :

module.exports = {
    env: {
        browser: true,
...
}

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