ENOENT: no such file or directory, stat './tsconfig.json'
See original GitHub issueI have started a new react app and defined baseUrl as “./” on my tsconfig.json. Added eslint-import-resolver-typescript and empty settings on .eslintrc.js but still got Unable to resolve path error, despite imports worked as expected. Tried to specify tsconfig.json location on project property but got title error. All package.json, tsconfig.json and .eslintrc.js are on root folder, code is on /src.
These are my current config files:
.eslintrc.js:
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: [
"eslint:recommended",
"plugin:import/recommended",
"plugin:react/recommended",
"airbnb",
"plugin:prettier/recommended",
"plugin:import/typescript",
],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 12,
sourceType: "module",
},
settings: {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"],
},
"import/resolver": {
typescript: {},
},
},
plugins: ["import", "react", "@typescript-eslint"],
rules: {
"react/react-in-jsx-scope": "off",
"react/jsx-filename-extension": [
2,
{ extensions: [".js", ".jsx", ".ts", ".tsx"] },
],
},
};
}
{
"name": "react",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"connected-react-router": "^6.9.1",
"feather-icons": "^4.28.0",
"history": "^5.0.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-redux": "^7.2.4",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"redux": "^4.1.0",
"typescript": "^4.3.2",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.25.0",
"@typescript-eslint/parser": "^4.25.0",
"eslint": "^7.27.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-import-resolver-typescript": "^2.4.0",
"eslint-plugin-import": "^2.23.3",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-react": "^7.23.2",
"eslint-plugin-react-hooks": "^4.2.0",
"prettier": "^2.3.0"
}
}
.tsconfig.json:
{
"compilerOptions": {
"noFallthroughCasesInSwitch": true,
"target": "es5",
"module": "esnext",
"baseUrl": "./",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"noImplicitAny": false,
"strict": true
},
"include": ["src"]
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:13
Top Results From Across the Web
Issues
ENOENT : no such file or directory, stat '. ... All package.json, tsconfig.json and .eslintrc.js are on root folder, code is on /src....
Read more >no such file or directory in tsconfig.app.json using angular 4?
I researched this issue for the solution: Your Angular project has a tsconfig.app.json. This file is ...
Read more >Can't find the tsconfig.json file
ENOENT : no such file or directory, open 'src/client/tsconfig.json'. The tsconfig.json has and always been in the src directory.
Read more >Parsing Error: Cannot read file 'tsconfig.json'
Another cause of the "Parsing Error: Cannot read file 'tsconfig.json'" is when we open our code editor in a different directory than the...
Read more >Unable to resolve path to module 'next/app'.eslint : r/nextjs
eslint. &. Resolve error: ENOENT: no such file or directory, stat './tsconfig.json'. Any ideas why?
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I came up this issue because I had a quite similar error. In my case I have a Monorepo using Turborepo. In my Next.js app in the subfolder
apps/next-frontendI had the problem, that ESLint in VSCode couldn’t resolve the paths to my modules but while compiling everything worked well. If I put"project": "./tsconfig.json", it didn’t work in the IDE but while compiling. When I set"project": "apps/next-frontend/tsconfig.json"it worked in the IDE but not for compilation.With the following options now everything is working without error - while compiling and in VSCode.
Maybe this helps someone else who comes across this issue. 😃
If you mean
Unable to resolve path to module 'src/components/Example', I can reproduce it bynode ./project/node_modules/.bin/eslint ./project/src/App.tsx, that is because the defaultprojectvalue isprocess.cwd(): https://github.com/alexgorbatchev/eslint-import-resolver-typescript/blob/master/src/index.ts#L216It can be resolved by ESLint
conext.getCwd(), butcontextis not available in ESLint import resolver right now.So the simple fix for now is setting
projectto be__dirnamewhich represents__dirname + '/tsconfig.json'actually: