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!