Error: Unable to load the parser '@typescript-eslint/parser' as specified in the configuration file '.eslintrc.json' for eslint-config-next/core-web-vitals

When starting a new Next.js application with the specific configuration below:

✔ What name do you want to give your project? … app
✔ Do you want to use TypeScript? … No / [Yes]
✔ Do you want to use ESLint? … No / [Yes]
✔ Do you want to use Tailwind CSS? … No / [Yes]
✔ Do you want to use the `src/` directory? … No / [Yes]
✔ Do you want to use App Router? (recommended) … No / [Yes]
✔ Do you want to customize the default import alias? … [No] / Yes

Webstorm version 2023.1.3 shows two errors related to ESLint and Prettier packages, which seem to be connected.

1. ESLint

Specifically complains about missing parser on all typescript XML files (.tsx).

ESLint error message

On looking at more details, the log displays:

SyntaxError: Failed to load parser '@typescript-eslint/parser' declared in '.eslintrc.json » eslint-config-next/core-web-vitals » /app/node_modules/eslint-config-next/index.js#overrides[0]': Unexpected token '?'

/app/node_modules/typescript/lib/typescript.js:139
    for (let i = startIndex ?? 0; i < array.length; i++) {
                             ^

SyntaxError: Unexpected token '?'
    at compileFunction (<anonymous>)
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/app/node_modules/@typescript-eslint/typescript-estree/dist/convert.js:29:25)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
Process finished with exit code -1

The configuration within the `.eslintrc.json` file is as follows:

{
  "extends": "next/core-web-vitals"
}

2. Prettier

After installing the prettier package using npm i -D prettier Attempting to format the code using the Ctrl+Alt+Shift+P shortcut results in an error for all file types (.ts, .tsx, .js, .jsx...):

Prettier error message

Looking into more details of the log:

/app/node_modules/prettier/index.cjs:481
  const comments = node.comments ?? (node.comments = []);
                                  ^
SyntaxError: Unexpected token '?'
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
Process finished with exit code -1

I have searched extensively for similar errors but haven't found a solution yet. I also tried using other IDEs like VSCode where both Prettier and ESLint work without any issues.

To replicate these errors, you can follow the steps outlined in the description.

My attempts to resolve this include:

  1. For ESLint:
  • Installing a local version of @typescript-eslint/parser using
    npm i -D @typescript-eslint/parser
    .
  • Adjusting the ESLint configuration by changing the parser configuration (in my case to @babel/eslint-parser)
  1. For Prettier:
  • Tried modifying the configurations in the `.prettierrc` file without success.

It appears that both packages are using a version of ECMAScript that does not support nullish coalescing operators (< ES2020), but I'm unsure how to control this. The issue with ESLint seems to be specific to Next.js, even though everything works fine in VSCode.

I was hesitant to report this issue to the Next.js team as it seems like a larger problem.

Answer №1

If you've found yourself facing a similar issue:

After delving into this problem for a week, I came to the realization that my default Node.js parser in WebStorm IDE was at version 12.22.9.

The reason behind this is my use of Linux Ubuntu 22.04 which already has a built-in version of Node.js available here (check your usr/bin/node). ESLint may no longer support this older version.

To get ESLint running smoothly on WebStorm, here are two options to consider:

  1. Remove the pre-installed Node.js version from Ubuntu 22.04 and install nvm, a Node.js version manager package. To do this:

    • Uninstall Node.js: sudo apt purge nodejs npm
    • [Skip if you already have nvm] Install nvm:
      curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
      (from nvm)
    • Select the desired node interpreter in WebStorm. Go to WebStorm, press Ctrl+Alt+S for Settings, navigate to
      Languages & Frameworks | Node.js.
      Choose the most suitable version. I opted for the latest version shown by nvm which is currently v16.13.1. Alternatively, you can create a .nvmrc file in your project's root directory to specify the Node.js version you want to maintain consistency across different machines or IDEs - useful for team collaborations.
  2. Select an appropriate Node.js version directly in WebStorm following the previous step

With these steps, ESLint and Prettier should function smoothly.

Answer №2

To easily switch the node interpreter in IntelliJ IDEA, go to Settings -> Languages & Frameworks -> Node.js and select a specific version from ~/.nvm/versions/node/v16.15.1/node. I have personally tested this method and can confirm that it works flawlessly.

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

Unfortunately, I am having difficulties implementing Exception Handling (both at the page level and global level) in my nextjs project. The error.js file is unable to catch errors thrown from

Take a look at my file structure https://i.stack.imgur.com/bpHdn.jpg app/(site)/users/page.jsx code is "use client"; import React from "react"; import UserTable from "@/components/partials/tables/UserTable"; const users = ...

How can one correctly import node modules in the handler function of next.js API?

I need to import bcrypt in a file located in my /api directory. // pages/api/login.js const bcrypt = require('bcrypt'); export default async function handler(req, res) { switch (req.method) { case 'POST': // do stuff with b ...

"Exploring the power of D3, TypeScript, and Angular 2

I am facing challenges incorporating D3 v4 with Angular 2 (Typescript). While exploring D3 v4, I have referred to several solutions on StackOverflow without success. I have imported most of the necessary D3 libraries and typings (utilizing TS 2.0) and adde ...

Merging an unspecified number of observables in Rxjs

My latest project involves creating a custom loader for @ngx-translate. The loader is designed to fetch multiple JSON translation files from a specific directory based on the chosen language. Currently, I am implementing file loading through an index.json ...

When there is data present in tsconfig.json, Visual Studio Code does not display errors inline for TypeScript

After creating an empty .tsconfig file (consisting solely of "{ }"), Visual Studio Code immediately displays errors both inline and in the "problems" section. Interestingly, when I populate the tsconfig.json file with data, these errors disappear. Is there ...

ReactJS rendition function fails to initiate

Currently, I am working on resolving the NestJS CORS issue. After some research, I have found that using rewrite is the best solution and decided to test it out. Following the instructions provided in this documentation enter link description here. Howeve ...

Rendering a React/Material UI class based on the state variable in a conditional manner

I am currently working on building a basic navbar setup using React and Material UI. I have encountered an issue where React-Router-Dom does not seem to be functioning within this particular project, and implementing it would be excessive for the simple ta ...

Deactivate the chosen tab by clicking the Mat-Tab button

I was trying to implement a way to disable the selected mat-tab and its elements when a button is clicked, //HTML <mat-tab-group #tabGroup> <mat-tab *ngFor="let subject of subjects" [label]="subject.name"> {{ subject.name }} ...

I'm having a hard time navigating through the Next.js route redirect to another language due to an invalid attempt

When I use route.push in NextJS to switch to a different language URL, I encounter the following error message ...

Utilizing HTML and Ionic 3.x: Implementing a for loop within the HTML file by utilizing "in" instead of "of"

I am working with multiple arrays of objects in my typescript file and I need to simultaneously iterate through them to display their contents in the HTML file. The arrays are always the same size, making it easier to work with. Here is what I currently ha ...

Check for user authentication in Next.js when integrating with Express backend

Within a different project, I've set up the following endpoint using expressjs as my backend: http://localhost:3001/auth/login # to login { username: string, password: string } http://localhost:3001/auth/whoami # to check if you're logged in or n ...

What is the best method for implementing notifications/alerts in React in a way that is both efficient and functional? We require a universal function that can be easily integrated and utilized across

Is there a way to implement a notification or alert function that displays messages and disappears after a specific time? I am looking for a library or implementation that can handle this functionality. The requirement is to have a function that can be ca ...

Ensure the navigation bar is horizontally centered by utilizing Next.js and Tailwind CSS

Hello, I'm looking to horizontally align my navbar. Can someone help me with this? <nav className='flex items-stretch flex-wrap bg-blue-300 p-3 '> <div className='flex px-4 align-middle'> <Link href ...

A guide on iterating through a JSON object fetched using Http in Angular 2/Typescript

I am attempting to extract specific data from my JSON file using http. The structure of the JSON is as follows: [{"name":"Name1","perc":33},{"name":"Name2","perc":22},{"name":"Name3","perc":41}] To loop through this retrieved object, I use the following ...

Attempt to re-establish connection to server callback in Angular 2 upon encountering failure

tag, I have created an API parent class where all the necessary methods are implemented for server communication. The ApiService class is injected with Http and MdSnackBar services to handle HTTP requests and display snack bar messages. The get() method ...

Retrieving information selectively using useSWRImmutable

Having issues fetching data using useSWRImmutable. The problem arises when attempting to display the fetched data inside the UserRow component. Even though I can successfully print the data outside of the UserRow component, any console.log() statements wi ...

Using Next.js in conjunction with Tailwind CSS and the shadcn/ui library to tackle the issue of preventing overscroll from creating

As I delve into a Next.js project, my goal is to use Tailwind CSS to craft an interface featuring a sidebar on the left, a header at the top, and a main content area. However, an issue has surfaced where users can over-scroll, leading to a blank space appe ...

What causes materialui styles to vanish upon refreshing in nextjs?

After consulting the materialui documentation (https://material-ui.com/guides/server-rendering/), I was able to find a solution, but I am still unsure of the underlying reason. Why does the style work initially during rendering but disappear upon subs ...

The Art of Typing in TypeScript Classes

I am working with an interface or abstract class in TypeScript, and I have numerous classes that implement or extend this interface/class. My goal is to create an array containing the constructors of all these subclasses, while still ensuring that the arra ...

When using a function as a prop in a React component with Typescript generics, the type of the argument becomes unknown

React version 15 or 18. Typescript version 4.9.5. When only providing the argument for getData without using it, a generic check error occurs; The first MyComponent is correct as the argument of getData is empty; The second MyComponent is incorrect as t ...