Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

eslint 9 + typescritp without type module

I'm trying to upgrade eslint to v9 for next-json

I followed the official Getting started guideline, but in order to make it work I need to set "type": "module" in the package.json file.

Since I'm distributing the package both as CJS and ESM, I'm warried this setting may create issues on the CJS distributed version.

Can I safely distribute the package with this setting as well?

like image 818
Daniele Ricci Avatar asked Oct 12 '25 01:10

Daniele Ricci


1 Answers

Yes, you can. If you can't set "type": "module" in your package.json, you can still either:

  • Force the ESLint config file to execute as a module by naming it eslint.config.mjs instead of *.cjs or .js
  • Use CommonJS syntax in the ESLint config file. Instead of imports and export default [ ... ], you'd use requires and module.exports = [ ... ]:
    const eslint = require('eslint');
    const tseslint = require('typescript-eslint');
    
    module.exports = [
      eslint.configs.recommended,
      ...tseslint.configs.recommended,
    ];
    

This question came up in the typescript-eslint docs: see https://github.com/typescript-eslint/typescript-eslint/pull/927 and its linked issues. Naming the ESLint config file eslint.config.mjs is what the typescript-eslint docs now do.

like image 122
Josh Avatar answered Oct 14 '25 17:10

Josh