DEV Community

Cover image for Import and export declarations are not supported yet (in TS)
Michal Bryxí
Michal Bryxí

Posted on

Import and export declarations are not supported yet (in TS)

The problem

When trying to use import or export statements in TypeScript (*.ts) files eslint complains:

Import and export declarations are not supported yet.
eslint(node/no-unsupported-features/es-syntax)
Enter fullscreen mode Exit fullscreen mode

Solution

Add following rule config to your eslint settings:

//.eslintrc.js
module.exports = {
  ...
  rules: {
    "node/no-unsupported-features/es-syntax": [
      "error",
      { ignores: ["modules"] },
    ],
  },
  ...
}
Enter fullscreen mode Exit fullscreen mode

Notes

My full eslint configuration for reference:

//.eslintrc.js
module.exports = {
  root: true,
  parser: "@typescript-eslint/parser",
  parserOptions: {
    ecmaVersion: 2018,
    sourceType: "module",
  },
  plugins: ["node", "unicorn", "prettier", "@typescript-eslint"],
  extends: [
    "eslint:recommended",
    "plugin:node/recommended",
    "plugin:unicorn/recommended",
    "plugin:prettier/recommended",
    "plugin:@typescript-eslint/recommended",
    "prettier",
  ],
  env: {
    node: true,
  },
  rules: {
    "no-console": "error",
    "unicorn/no-array-reduce": "off",
    "prettier/prettier": "error",
    "@typescript-eslint/no-var-requires": "off",
    "node/no-unsupported-features/es-syntax": [
      "error",
      { ignores: ["modules"] },
    ],
  },
  settings: {
    node: {
      tryExtensions: [".js", ".json", ".node", ".ts"],
    },
  },
};
Enter fullscreen mode Exit fullscreen mode

This only works when I have following settings in package.json:

//package.json
{ 
  ...
  "type": "commonjs",
  ...
}
Enter fullscreen mode Exit fullscreen mode

References


Photo by Brett Jordan on Unsplash

Top comments (4)

Collapse
 
verberden profile image
Sergei Novikov

Hello! I want you to ask about unicorn plugin. What for we need to use it?

Collapse
 
michalbryxi profile image
Michal Bryxí

Hi Sergei unicorn is popular eslint plugin that adds some extra formatting rules. You don't need it at all. I attached the full config only because I think setting up all the extends / plugins is very confusing and this should give the reader ability to have copy&paste solution. If you know what you're doing, adding the extra rules option is a way to go.

Collapse
 
verberden profile image
Sergei Novikov

Michal thanks! I google it but wasn't sure. Actually i'm starting to use airbnb's rules in my project and have never heard about unicorn before. And I'm wondering if anyone has compared them?

Thread Thread
 
michalbryxi profile image
Michal Bryxí

Not sure tbh. Quick look at the Airbnb one it seems that:

  • It requires more involvement (have to use additional packages)
  • They have some rules that do care about old browsers
  • Are the rules auto-fixable? Maybe another article would be good for that.