0

I have this tsconfig.json file with paths that I need to resolve in a certain way.

{
    "compilerOptions": {
        "allowSyntheticDefaultImports": true,
        "jsx": "react-native",
        "lib": ["dom", "esnext"],
        "moduleResolution": "node",
        "noEmit": true,
        "skipLibCheck": true,
        "resolveJsonModule": true,
        "strict": true,
        "noImplicitAny": false,
        "baseUrl": "./",
        "paths": {
            "components/*": ["./app/components"],
            "components/*/*": ["./app/components/*/index"], // This line does not work
            "services/*": ["./app/services"],
            "app/*": ["./app"],
            "navigation/*": ["./app/navigation"],
            "theme/*": ["./app/theme/*"]
        }
    }
}

The highlighted line is throwing this error:

Pattern 'components/*/*' can have at most one '*' character.

I tried every possible solution and I cannot find any single solution whatsoever. It seems impossible to even find the same error message somewhere on the internet. Any helpful suggestions would be massively appreciated.

1 Answer 1

1

Development

npm i -save-dev tsconfig-paths/register

tsconfig.json

{
 "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@src/*": ["src/*"],
    },
  }
}

package.json

"scripts": {
  dev: "ts-node -r tsconfig-paths/register src/index.ts"
}

Build

npm i -save-d ttypescript @zerollup/ts-transform-paths

tsconfig.json

{
 "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@src/*": ["src/*"],
    },
  }
 "plugins": [
      {
          "transform": "@zerollup/ts-transform-paths",
      }
  ],
}

package.json

"scripts": {
  build: "ttsc -P ./tsconfig.json"
}
Sign up to request clarification or add additional context in comments.

1 Comment

minor correction, the package to install is just tsconfig-paths, so do npm i -save-dev tsconfig-paths

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.