ember-cli / eslint-plugin-ember

An ESLint plugin that provides set of rules for Ember applications based on commonly known good practices.
MIT License
261 stars 202 forks source link

ESLint throws "Must use import to load ES Module..." #1346

Closed Timbuktu1982 closed 2 years ago

Timbuktu1982 commented 2 years ago

Hey there...

eslint throws following error: Parsing error: Must use import to load ES Module: /var/www/[addon]/node_modules/eslint-scope/lib/definition.js require() of ES modules is not supported. require() of /var/www/[addon]/node_modules/eslint-scope/lib/definition.js from /var/www/[addon]/node_modules/babel-eslint/lib/require-from-eslint.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules. Instead rename definition.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /var/www/[addon]/node_modules/eslint-scope/package.json. eslint

I only use "import" to require modules/files, e.g. like: import Component from "@glimmer/component"; import { action, computed, get, set } from "@ember/object"; import { inject as service } from "@ember/service"; import { tracked } from "@glimmer/tracking"; import { camelize } from "@ember/string";

I have following plugins/version installed: "babel-eslint": "10.1.0", "eslint": "8.0.1", "eslint-config-prettier": "8.3.0", "eslint-plugin-ember": "10.5.7", "eslint-plugin-node": "11.1.0", "eslint-plugin-prettier": "4.0.0", "eslint-plugin-qunit": "7.0.0", ..... "ember-cli": "3.28.3", "ember-source": "3.28.1", ....

Following parser-settings in .eslintrc.js: parser: "babel-eslint", parserOptions: { ecmaVersion: 8, sourceType: "module", ecmaFeatures: { legacyDecorators: true, }, }, plugins: ["ember"],

What can i do?

bmish commented 2 years ago

I think you just need to upgrade from babel-eslint to @babel/eslint-parser to support ESLint 8.

This issue was mentioned here too: https://github.com/ember-cli/ember-cli/pull/9669

Timbuktu1982 commented 2 years ago

I think you just need to upgrade from babel-eslint to @babel/eslint-parser to support ESLint 8.

This issue was mentioned here too: ember-cli/ember-cli#9669

Hey bmish, thank you. I had run this solution before, but i doesn't know at this time, that i have 2 problems. After install @babel/eslint-parser i see no eslint-messages more.

The solution for me was to add a option in vscode-settings: "eslint.validate": [ "javascript", "javascriptreact", "html", "typescriptreact" ]

THX