un-ts / eslint-plugin-sonar

ESLint rules extracted from SonarJS
https://github.com/SonarSource/SonarJS
MIT License
42 stars 2 forks source link

Error with Flatconfig, `Named export 'SyntaxKind' not found. The requested module 'typescript' is a CommonJS module` #101

Closed ElPrudi closed 11 months ago

ElPrudi commented 1 year ago

I'm currently switching from the legacy format .eslintrc.js to eslint.config.js and I'm importing this plugin as an esm module. Due to how TypeScript is built, being a commonjs file, you can't use explicit named exports.

Your file uses:

import ts__default, { SyntaxKind, TypeFlags } from 'typescript';

But should rather be this:

import ts__default from 'typescript';
const { SyntaxKind, TypeFlags } = ts__default

or this:

import ts__default, { type SyntaxKind, type TypeFlags } from 'typescript'; // type imports are removed after ts compilation
JounQin commented 1 year ago

@ElPrudi Sorry for the delay.

I think that's because we're not using @rollup/plugin-commonjs, I'll fix it ASAP.


The current workaround is still using commonjs in ESM:

import { createRequire } from 'node:module'

const require = createRequire(import.meta.url)

require('eslint-plugin-sonar')
JounQin commented 1 year ago

Hmm... I don't quite understand, I tried to use @rollup/plugin-commonjs, but the output remains same, I'll fix this in another way. And this could be an issue of rollup itself.