React Native Typescript babel-plugin-module

我可以毫无问题地将模块解析器与 Javascript 一起使用。实际上,我可以在运行时毫无问题地将它与 Typescript 一起使用,但在开发部分我找不到Cannot find module or its corresponding type declerations问题的解决方案。我正在寻找答案我做错了哪一部分?


以下是文件:


.babelrc


{

  "presets": ["module:metro-react-native-babel-preset"],

  "plugins": [

    [

      "module-resolver",

      {

        "root": ["./src"],

        "alias": [

          { "@shared-components": "./shared/components" },

          { "@shared-constants": "./shared/constants" },

          { "@shared-theme": "./shared/theme" },

          { "@font-size": "./shared/theme/font-size" },

          { "@api": "./services/api/index" },

          { "@fonts": "./shared/theme/fonts/index" },

          { "@colors": "./shared/theme/colors" },

          { "@theme": "./shared/theme/index" },

          { "@services": "./services" },

          { "@screens": "./screens" },

          { "@utils": "./utils/" },

          { "@assets": "./assets/" }

        ],

        "extensions": [".js", ".jsx", ".ts", ".tsx"]

      }

    ]

  ]

}

tsconfig.json文件


{

  "compilerOptions": {

    "target": "esnext",

    "module": "esnext",

    "lib": ["esnext"],

    "allowJs": true,

    "jsx": "react-native",

    "noEmit": true,

    "isolatedModules": true,

    "strict": true,

    "moduleResolution": "node",

    "allowSyntheticDefaultImports": true,

    "esModuleInterop": true,

    // ? Custom ones

    "skipLibCheck": true,

    "resolveJsonModule": true,

    "noImplicitAny": true,

    "strictNullChecks": true,

    "strictFunctionTypes": true,

    "strictPropertyInitialization": true,

    "noImplicitThis": true,

    "alwaysStrict": true,

    "noUnusedLocals": true,

    "noUnusedParameters": true,

    "noImplicitReturns": true,

    "noFallthroughCasesInSwitch": true,

    "forceConsistentCasingInFileNames": true,

    // ? Babel Plugin Module Resolver



FFIVE
浏览 73回答 1
1回答

一只萌萌小番薯

您的配置中的映射方式paths看起来不正确。正确的应该是:paths": {  "@screens/*": ["./screens/*"], // You need to specify prefix `/*` as well  // others ...}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript