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

How can you create an interface where the value type is determined by the key, but not all keys are predefined?

Below is an illustration of a data structure that I aim to define as a type in TypeScript: const dataExample = { Folder: { "Filename.js": { lines: { total: 100, covered: 80, ...

Issue encountered with the local mongo connection, but smooth sailing on Vercel in the production environment

I'm currently facing an issue where my MongoDB database successfully connects in production, but encounters connection errors when trying to connect in localhost. Let me walk you through my setup: Backend (lib/mongodb.js): import { MongoClient } from ...

A warning has been issued: CommonsChunkPlugin will now only accept one argument

I am currently working on building my Angular application using webpack. To help me with this process, I found a useful link here. In order to configure webpack, I created a webpack.config.js file at the package.json level and added the line "bundle": "web ...

Is it possible to transform a ReadonlyArray<any> into a standard mutable array []?

At times, when working with Angular functions and callbacks, they may return a ReadonlyArray. However, I prefer using arrays in the traditional way and don't want to use immutable structures like those in Redux. So, what is the best way to convert a ...

The error message "Type 'IPromise<{}>' is not compatible with type 'IPromise<TemplatesPagingModel>' in typescript version 2.8.0" is displayed

Currently, I am working on an AngularJS framework (version 1.5.8) with the latest TypeScript files (version 2.8.0). However, after updating to the most recent TypeScript version, the code below is not compiling. Implementation of Angular interface: inter ...

Query MongoDB data using API calls

Currently, I am grappling with the issue of filtering data in mongodb Atlas through API requests. Here is my json structure: { _id: ObjectId, level: number, names: Array } I have successfully learned how to filter by _id. By passing the id through the url ...

Error in Next.js with React Aria: ID prop does not match

While experimenting with React Aria in Next.js, I came across an error message that reads: Warning: Prop id did not match. Server: "react-aria-3" Client: "react-aria-10" Even after wrapping _app.js with the SSRProvider component, the i ...

How to attach a local directory to a Docker container

I am currently working on containerizing my Next.js app for production purposes and have encountered an issue with the setup. Here is how my `docker-compose.yml` file is set up: version: '3.9' services: app: container_name: webapp buil ...

What are the benefits of adding member functions to the data structures of React.js store?

Using React.js and Typescript, I store plain Javascript objects in the React.js store. These objects are sometimes received from the server without any member functions, but I wish to add functions for better organization. Instead of having to rely on exte ...

Exploring the challenges of using WordPress as a headless CMS in conjunction with Next.js, especially when it comes to efficiently rendering post content

Although my post content is displaying properly, I am unable to get the code highlights to work for the examples included in my post. To provide some context, I am utilizing WordPress GraphQL backend and Next.js on the frontend by referencing this tutorial ...

Typescript error message TS2314: One type argument is required for the generic type 'Array<T>'

I recently started my journey in learning typescript and have written some basic code. class Learning { subjects: Array[string]; hoursPerDay: number; constructor(subj: Array[string], hrs: number) { this.subjects = subj; thi ...

Develop a specialized data structure for rows in ag grid that can adapt to changes

I have been working on creating an independent component using ag-grid. The column definitions are passed to this component from my application as input properties, defined like this: interface ColumnDef { field: string; headerName: string; } @Input() ...

Why is @faker-js/faker not usable in a TypeScript project, showing undefined error, while the older "faker" import still functions correctly?

Currently, my packages.json file includes: "faker": "^5.5.3", "@types/faker": "^5.5.3", I am sticking with version 5.5.3 due to another project dependency (codecept) that requires this specific version. The ...

Guide on associating user IDs with user objects

I am currently working on adding a "pin this profile" functionality to my website. I have successfully gathered an array of user IDs for the profiles I want to pin, but I am facing difficulties with pushing these IDs to the top of the list of profiles. My ...

The reCAPTCHA feature in Next.js form is returning an undefined window error, possibly due to an issue with

Trying to incorporate reCAPTCHA using react-hook-form along with react-hook-recaptcha is posing some challenges as an error related to 'window' being undefined keeps popping up: ReferenceError: window is not defined > 33 | const { recaptchaL ...

An issue arises when trying to update state using useState in TypeScript

In our system, we have a state that contains an array of objects: interface Product { id: number; status: boolean; color: string; price: number; } const productList: Product[] = [ { id: 1, status: true, color: 'yellow', ...

I am running into an issue where the Google App Engine standard is not able to compress my Next.js/Express

I am currently exploring solutions to enable compression on the output of my Next.js/Node.js/Express application when deployed on Google App Engine (standard version). It appears that the issue lies in the fact that: 1) Google's load balancer strips ...

Troubleshooting a Cache Issue in Your Next.js Application

Whenever I attempt to run 'npm run build', an error crops up that seems to be linked to the css and fonts. Unfortunately, I am unsure of how to tackle this problem. It's perplexing as the app functions perfectly fine in development mode. Th ...

Tips on fixing server/client content mismatch caused by browser auto translate

While constructing a website with next14, storyblok, and i18n, I encountered an issue in the browser related to the automatic Google translate feature for Georgian and English languages. Despite setting Georgian as the default language in my app, when swit ...

What is the proper way to set up socket.io in a Next.js project using pm2?

After successfully creating a video chat feature for my existing Next.js application, I encountered some challenges when trying to install it on the application and running it with pm2. My current implementation failed to work as expected: const nextApp = ...