简体   繁体   English

Typescript 路径在 tsconfig.json 中不起作用

[英]Typescript path not working in tsconfig.json

I have this tsconfig.json file with paths that I need to resolve in a certain way.我有这个 tsconfig.json 文件,其中包含我需要以某种方式解析的路径。

{
    "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 inte.net.似乎甚至不可能在 inte.net 的某处找到相同的错误消息。 Any helpful suggestions would be massively appreciated.任何有用的建议将不胜感激。

Development发展

npm i -save-dev tsconfig-paths/register

tsconfig.json tsconfig.json

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

package.json 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 tsconfig.json

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

package.json package.json

"scripts": {
  build: "ttsc -P ./tsconfig.json"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM