Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

typescript-eslint "SyntaxError: Cannot use import statement outside a module"

I try settup eslint with typescript-eslint. My config from docs:

import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

export default tseslint.config(
  eslint.configs.recommended,
  ...tseslint.configs.recommended
);

In IDE error:

import eslint from '@eslint/js';
^^^^^^

SyntaxError: Cannot use import statement outside a module
like image 960
Timofey Goncharov Avatar asked Aug 12 '26 06:08

Timofey Goncharov


1 Answers

You need to set "type": "module" to your package.json file. See https://eslint.org/docs/latest/use/configure/configuration-files#configuration-file

If your project does not specify "type": "module" in its package.json file, then eslint.config.js must be in CommonJS format, such as:

// eslint.config.js
module.exports = [
    {
        rules: {
            semi: "error",
            "prefer-const": "error"
        }
    }
];

like image 123
Gideon Avatar answered Aug 15 '26 00:08

Gideon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!