xojs/xo

"Parsing error: ImportDeclaration should appear when the mode is ES6 and in the module context." in update to 0.45.0

muziejus opened this issue · 4 comments

Upgrading from 0.44.0 to 0.45.0 has caused xo to fail giving this error. I've found documentation about it for eslint, but that documentation is all very old, and I still get the error with setting my eslint parseroptions like this:

  parserOptions: {
    ecmaVersion: 12,
    sourceType: "module",
    ecmaFeatures: {
      legacyDecorators: true,
    },
  },

The parser in the .xo-config.json is set to babel-eslint, which is at 10.1.0. This is in an ember project, using node 14.18.0.

Running eslint and prettier work fine, outside of complaining about not understanding some rules.

babel-eslint is unmaintained. You should move to @babel/eslint-parser.

Thanks. That seems to have worked. It took a little juggling, though. My new .eslintrc.js includes:

  parser: "@babel/eslint-parser",
  parserOptions: {
    requireConfigFile: false,
    ecmaVersion: 12,
    sourceType: "module",
    ecmaFeatures: {
      legacyDecorators: true,
    },
    babelOptions: {
      plugins: [
        [
          "@babel/plugin-proposal-decorators",
          { "legacy": true },
        ],
      ],
    },
  },
  plugins: ["ember"],

I needed to add the babelOptions line so that decorators (used extensively in Ember) would work. I reproduced it in .xo-config.json:

  "parser": "@babel/eslint-parser",
  "parserOptions": {
    "requireConfigFile": false,
    "ecmaFeatures": {
      "legacyDecorators": true
    },
    "babelOptions": {
      "plugins": [
        [
          "@babel/plugin-proposal-decorators",
          { "legacy": true }
        ]
      ]
    }
  },

I had to yarn add -D @babel/plugin-proposal-decorators, and I don't know if I have to keep the ecmaFeatures property, but I won't fuss with this now that it's working...

Thanks @muziejus your solution really helped me. :)

@sindresorhus
@muziejus

Your posts were helpful! Thank you!