What steps can I take to resolve the issue of "No ESLint configuration found" when working with files located outside the directory containing .eslintrc.js? This problem occurs specifically when attempting to utilize an enum value

The application structure

Currently, I am in the process of developing a full-stack app with Node.js, TypeScript, and Vue. Here is an overview of my folder structure:

<project root>
  model/
  front/
    src/
    node_modules/
    package.json
    .eslintrc.js     // please note its location
    ...
  back/
  node_modules/
  package.json
  ...

The front/ directory was created based on the app generated by vue-cli. As a personal preference, I prefer keeping the frontend node_modules separate from the backend ones. Therefore, the structure of front/ aligns with the standard layout for a Vue app.

The shared model (for both frontend and backend)

I have a TypeScript model that is common to both frontend and backend, stored in:

model/
  objects.ts
  api.ts

To utilize api.ts in the frontend section, I have front/src/store/api.ts which simply re-exports as:

// re-export from fullstack common model
export * from '../../../model/api'

This approach has been working smoothly with interfaces defined in model/api.ts and model/objects.ts. For instance, I can easily do:

import { TestApiResponse } from '../api'
...
const testUser: TestApiResponse = response.data;

in front/src/store/modules/user.ts.

The issue at hand

I recently attempted to introduce:

export enum Endpoints {
  TestApi = 'testApi',
}

with the intention of using it in both frontend and backend, similar to how the interfaces are utilized. Thus, the updated minimal api.ts file now includes:

import { UserBase } from './objects'

export enum Endpoints {
  TestApi = 'testApi',
}

export interface TestApiResponse extends UserBase {}

Initially, this change did not cause any issues. However, upon making modifications in user.ts such as:

const response = await axios.get(Vue.prototype.$apiRoot + Endpoints.TestApi);

The development server and building processes began displaying errors like:

Failed to compile.

../model/api.ts Module build failed (from ./node_modules/eslint-loader/index.js):
Error: No ESLint configuration found in <project root>\model.
at CascadingConfigArrayFactory._finalizeConfigArray (<project root>\front\node_modules\eslint\lib\cli-engine\cascading-config-array-factory.js:432:19)
...

This discrepancy arises due to the usage of enum values as opposed to types, along with the fact that

<project root>/model/api.ts
resides outside <project root>/front/. This arrangement seems to conflict with the presence of .eslintrc.js within <project root>/front/. Any insights on why this occurs or suggestions on resolving this dilemma would be greatly appreciated.

(Attempts to rectify by moving .eslintrc.js to the root folder or model/ proved ineffective).

PS: Sharing here the content of .eslintrc.js established through vue cli:

module.exports = {
  root: true,
  env: {
    node: true
  },
  'extends': [
    'plugin:vue/essential',
    'eslint:recommended',
    '@vue/typescript/recommended'
  ],
  parserOptions: {
    ecmaVersion: 2020
  },
  rules: {
    'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
  }
}

PPS: Upon relocating .eslintrc.js to the root folder, encountered the following error when running npm run serve:

Module build failed (from ./node_modules/eslint-loader/index.js):
Error: Failed to load config ""@vue/typescript/recommended" to extend from.
Referenced from: <project root>\.eslintrc.js
...

Furthermore, duplicating .eslintrc.js in the root folder resulted in identical errors post restarting npm run serve. It appears additional dependencies may need installation in the root package.json, yet specifics remain unclear (frontend/node_modules/@vue/ does not house typescript/recommended). Deleting '@vue/typescript/recommended' segment from the root's .eslintrc prompted:

<project root>\model\api.ts
  4:8  error  Parsing error: Unexpected token enum

This situation indicates a necessity to reconfigure eslint for TypeScript from scratch. Following guidance from this source proved unfruitful. Attempting steps like:

  1. npm i -D eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin
  2. Including
    plugins: [ '@typescript-eslint' ]
    and extending
    'plugin:@typescript-eslint/eslint-recommended', 'plugin:@typescript-eslint/recommended'
    in .eslintrc

Unfortunately, still faced with the dreaded Unexpected token enum message. Perhaps opting for eslint setup via vue cli in a full-stack project might not be the most suitable approach.

Answer №1

Encountered a similar issue before, and I found that the solution was to use the @vue/eslint-config-typescript plugin. Installing this plugin did the trick for me, although I had to ensure it was compatible with my other dependencies.

Furthermore, it's important to understand that ESLint operates based on the concept of Сascading and Hierarchy:

ESLint offers two methods for using configuration files.

The first method involves utilizing either the .eslintrc.* or package.json files. ESLint will automatically search for these files in the same directory as the file being linted, as well as in each parent directory all the way up to the root directory of the filesystem (/) [...]

To address this issue, you simply need to relocate your .eslintrc.js from the front directory to the <project root> directory, as follows:

<project root>
  .eslintrc.js // applies to all subdirectories, including "model/"
  model/
  front/
    src/
    node_modules/
    package.json
  back/
  node_modules/
  package.json

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error encountered when trying to use the .find function in Typescript: "The expression is not callable."

Environment Details: typescript 4.5.5 Error Summary An issue occurred stating: "This expression is not callable. Each member of the union type '{ <S extends User>(predicate: (this: void, value: User, index: number, obj: User[]) => value ...

An issue occurred in the modal window following the relocation of project files

I encountered an issue with the modal in my Nativescript project after rearranging a few project files, including the modal. I updated the imports and deleted any compiled JavaScript files to ensure that my project could recompile correctly. Although I&ap ...

Challenges arise when trying to extract parameters in Nuxt 3

Hey everyone, I've been encountering some issues with extracting params from my route in Nuxt 3. The format of my dynamic route is exam_[id]_[applicant_id].vue and once loaded, the URL appears like this: http://localhost:3000/e-recruitment/exam_cl96q ...

Choose to either push as a single object or as individual items

I have a quick question that I'd like to get some clarity on. Can someone explain the distinction between these two code snippets: export const addToCart = function(product, quantity){ cart.push({product, quantity}); console.log(`${quantity} ...

Can Vue 3 Teleport only function to transport elements outside of the Vue environment?

Vue 3 introduces the Teleport feature, replacing the portal-vue plugin in Vue 2. However, I encountered an issue where it seems impossible to teleport a component to a place controlled by Vue within the app itself. It only seemed to work when porting compo ...

Simply output the integer value

Recently, I've been working on a function that I'm trying to condense into a one-liner code for a challenge on Codewars. You can find the problem here. Here's the code snippet that I currently have: export class G964 { public static dig ...

A step-by-step guide on validating two password fields using Joi in TypeScript React

I have created a versatile form component using TypeScript called AbstractForm. This component is intended to be inherited by other components such as LoginForm, RegisterForm, and so on. Currently, I am working on a component named DerivedForm. The validat ...

The number of keys in the related object must correspond to the length of the array in Advanced Generic Types

Can we achieve type safety across rows and columns by having one object define the structure of another? Starting Point: export interface TableColumn { name: string; type: "string" | "number" | "action"; id: string; } ...

updating firebase data using Angular

Currently, I am attempting to insert a new object into my Firebase database export class AppComponent { courses$: AngularFireList<any[]>; course$;ang author$ constructor(db: AngularFireDatabase) { this.courses$ = db.list('/courses ...

Tips for resolving TypeScript issues with Vuex mapGetters

When utilizing mapGetters, TypeScript lacks insight into the getters linked to the Vue component, leading to error messages. For instance: import Vue from 'vue'; import { mapActions, mapGetters } from 'vuex'; export default Vue.extend ...

Starting Out with Typescript Types - Unidentified term 'angular'

We are currently working on revitalizing an older AngularJS project by migrating it to .Net Core 3.1. As part of this process, we are looking to transition our scripts to TypeScript. While the project is functioning properly without TypeScript, we believe ...

Upon initial loading, the default sidenav in Angular is not selected

I need to ensure that the sidenav loads the basic page during the initial load. This is controlled by the routing.ts file shown below: import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; i ...

Guide to importing a JavaScript module as any type without using a declaration file (d.ts)

Looking to bring a js module into my ts app. Is there a way to achieve this without creating a d.ts file? If not, how can it be declared as any in the d.ts file? Currently using //@ts-ignore to ignore the error. Appreciate any help! ...

Is it possible to pass component props to mapGetters in VueX?

Currently, I am in the process of creating a universal input Vue component. My main goal right now is to fetch the initial value from the store before focusing on manipulating the data within the input. Here's what I have so far: This seems to be wor ...

Troubleshooting: Unable to locate .vue.d.ts file during declaration generation with Vue, webpack, and TypeScript

Currently, I am developing a library using Typescript and VueJS with webpack for handling the build process. One of the challenges I'm facing is related to the generation of TypeScript declaration files (.d.ts). In my source code, I have Typescript ...

Error in Serializer when validating data with Vue3 frontend and Django backend

I built a Vue front end that gathers user data and files, then uses Axios to POST it to a Django Rest Framework endpoint. Below is the function code: import { ref } from "vue"; import axios from "axios"; const fields = ref({ audie ...

What steps should I take to ensure my images load properly in my Vue application while utilizing webpack and vue-loader?

Having recently ventured into Vue, I find myself delving into some older code for a Vue application and facing the issue of images not loading onto the page. Despite validating that my component's asset paths are accurate as an extension within my cod ...

Prevent the event listener in Vue from capturing events on child elements

As part of my Vue project, I am working on creating a modal that should close when the user clicks outside of the inner modal container. However, I have encountered an issue where adding an event listener to the parent element causes all children elements ...

I can't figure out why the header isn't showing up in my basic Angular application

As a newcomer to Angular, I have been working on creating a simple application for hands-on learning. I decided to utilize the shared.module.ts file to handle my header and then imported it into my app.module.ts. However, after running the application, I n ...

Transform the code provided by bundleMDX into an HTML string specifically for RSS, all the while utilizing the mdx-bundler

I am currently working on developing an RSS reader and I need to convert the code returned by bundleMDX into a string. This is necessary so that I can utilize it with ReactDOMServer.renderToStaticMarkup(mdx) in my project. You can find a similar implement ...