vercel / next.js

The React Framework
https://nextjs.org
MIT License
126.89k stars 26.98k forks source link

eslint next 11 Parsing error: Cannot read file #26287

Open jimisaacs opened 3 years ago

jimisaacs commented 3 years ago

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.

housseindjirdeh commented 3 years ago

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?

jimisaacs commented 3 years ago

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

jimisaacs commented 3 years ago
cd client
yarn next lint
housseindjirdeh commented 3 years ago

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 commented 2 years ago

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

thisismydesign commented 2 years ago

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 > https://github.com/thisismydesign/nestjs-starter/pull/83

mikhaelesa commented 4 months ago

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 👍