Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eslint next 11 Parsing error: Cannot read file #26287

Open
jimisaacs opened this issue Jun 17, 2021 · 7 comments
Open

eslint next 11 Parsing error: Cannot read file #26287

jimisaacs opened this issue Jun 17, 2021 · 7 comments
Assignees
Labels
Linting Related to `next lint` or ESLint with Next.js.
Milestone

Comments

@jimisaacs
Copy link

jimisaacs commented Jun 17, 2021

What version of Next.js are you using?

11.0.0

What version of Node.js are you using?

v14.15.5

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

next export

Describe the Bug

when I run next build, it asked to install eslint-config-next. So I did to try the new feature.

after that I got numerous errors, seems like one for every page that look like this:

./src/pages/mypage.tsx
Error: Parsing error: Cannot read file '/full/path/to/git/clone/client/client/tsconfig.json'.

Yes, notice the client/client, that looks like the bug.

my git project structure is this:

root
  package.json
  client <--- where next build is run!!!
    package.json 
    tsconfig.json
    src
      pages   
        mypage.tsx

Expected Behavior

These errors should not happen. I also have my own eslint set up in the root of the repo, but I want to see what this feature offers before disabling it.

To Reproduce

Try to setup a project like what I've described, and run next build from the client directory.

@jimisaacs jimisaacs added the bug Issue was opened via the bug report template. label Jun 17, 2021
@housseindjirdeh
Copy link
Collaborator

Tried to quickly reproduce and couldn't unfortunately 😞.

Is next installed in client/package.json or in the root folder? Are you also seeing the same errors when running next lint?

@housseindjirdeh housseindjirdeh self-assigned this Jun 18, 2021
@jimisaacs
Copy link
Author

jimisaacs commented Jun 18, 2021

installed in client/package.json and client is a yarn workspace. Yes, same result with next lint.

@jimisaacs
Copy link
Author

cd client
yarn next lint

@timneutkens timneutkens added kind: bug and removed bug Issue was opened via the bug report template. labels Jun 21, 2021
@timneutkens timneutkens added this to the backlog milestone Jun 21, 2021
@housseindjirdeh
Copy link
Collaborator

Thanks for the clarification @jimisaacs. Unfortunately I can't seem to reproduce this issue, but could you try adding the following to your .eslintrc:

parserOptions: {
  project: "tsconfig.json",
  tsconfigRootDir: __dirname,
  sourceType: "module",
}

It sounds like ESLint is running for you on a separate directory than where tsconfig.json is located, so hopefully this fixes things.

@jclaveau
Copy link

jclaveau commented Jan 24, 2022

@housseindjirdeh I have the same issue in a fully reproduced use case (glad to CI) : thisismydesign/nestjs-starter#23

  • Lint is passing but not build
  • I tried several ways but nothing works

@thisismydesign
Copy link

thisismydesign commented Jul 25, 2022

I fixed this with the eslint dirs option:

src/client/next.config.js

module.exports = {
  eslint: {
    dirs: ['src/client'],
  },
};

After this, next build works.

I'm using it here: https://github.com/thisismydesign/nestjs-starter > thisismydesign/nestjs-starter#83

@samcx samcx removed the kind: bug label Apr 30, 2024
@mikhaelesa
Copy link

I fixed this with the eslint dirs option:

src/client/next.config.js

module.exports = {
  eslint: {
    dirs: ['src/client'],
  },
};

After this, next build works.

I'm using it here: https://github.com/thisismydesign/nestjs-starter > thisismydesign/nestjs-starter#83

2024 and still solved the issue 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Linting Related to `next lint` or ESLint with Next.js.
Projects
None yet
Development

No branches or pull requests

7 participants