Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

TypeScript Unable to resolve path (2307)

$
0
0

I'm building a react-native application. I've spent hours on this problem but nothing has helped me. I'm trying to use tsconfig paths for shortening my long relative imports:

My tsconfig file:

{"compilerOptions": {"allowJs": true,"allowSyntheticDefaultImports": true,"baseUrl": "./*","esModuleInterop": true,"isolatedModules": true,"jsx": "react","lib": ["es2017"],"module": "commonjs",  "moduleResolution": "node","noEmit": true,"paths": {"@theme/*": ["./src/theme/*"]        },"strict": true,"target": "esnext"    },"include": ["./src/**/*"    ],"exclude": ["node_modules"    ]}

I'm trying to import a module as follows:

import { theme } from '@theme'

However I'm getting the following error. This error shows with red underline in VSCode.

Cannot find module '@theme' or its corresponding type declarations.ts(2307)

But I get this error when I run command eslint as well.

I have also tried adding a package.json with a name property to theme directory, but it doesn't help either:

{"name": "@theme"}

I use the following versions:

"typescript": "^4.1.4""react-native": "0.63.3","react": "16.13.1","eslint": "^6.8.0",Node version: v12.21.0

Any help is appreciated!


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>