When I try to start linting on a file with the new configuration pattern, I get the following error:
PS C:\Users\test> npx eslint index.js
(node:10036) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
Oops! Something went wrong! :(
ESLint: 8.41.0
C:\Users\test\eslint.config.js:1
export default [
^^^^^^
SyntaxError: Unexpected token 'export'
at internalCompileFunction (node:internal/vm:73:18)
at wrapSafe (node:internal/modules/cjs/loader:1176:20)
at Module._compile (node:internal/modules/cjs/loader:1218:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
at Module.load (node:internal/modules/cjs/loader:1117:32)
at Module._load (node:internal/modules/cjs/loader:958:12)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
This my code for now just to try to get it to work
eslint.config.js
export default [
{
rules: {
semi: "error"
}
}
];
package.json
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint":"npx eslint index.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"eslint": "^8.41.0"
}
}
When I put "type: 'module'" inside my package.json, it will work of course. But I'm pretty sure this shouldn't be the solution. Does anyone have an idea?
eslint.config.mjs
worked for me – Aquinas