簡體   English   中英

無法訪問項目中的 tsconfig 路徑

[英]Can not acces tsconfig paths in project

我正在嘗試在 ts 文件中包含路徑嘗試在 stackoverflow 上可用的解決方案,但沒有一個對我有用 tsconfig.json

{
  "compilerOptions": {
    "strict": true,
    "baseUrl": "./app",
    "paths": {
      "@redux/*": ["redux/*"]
    },
    "include": [
      "./app/redux/**/*", "**/*.ts", "**/*.tsx"
  ],
  },
  "extends": "expo/tsconfig.base"
}

tsconfig.base.json

{
  "$schema": "https://json.schemastore.org/tsconfig",
  "display": "Expo",

  "compilerOptions": {
    "allowJs": true,
    "esModuleInterop": true,
    "jsx": "react-native",
    "lib": ["DOM", "ESNext"],
    "moduleResolution": "node",
    "noEmit": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "target": "ESNext"
  },

  "exclude": ["node_modules", "babel.config.js", "metro.config.js", "jest.config.js"]
}

嘗試在 app.tsx 中導入

import  {} from '@redux/store';// err Cannot find module '@redux/store' or its corresponding type declarations.

請提出一個解決方案(在反應應用程序中使用)。 還嘗試了其他路徑,例如組件。

結構 - <root>/app/components <root>/app/redux/store.tsx

你的路徑看起來不錯。

您可能需要使用tsconfig-paths 之類的工具來解析這些路徑名。

然后,您可以在執行構建的 package.json 文件中添加類似以下內容。

ts-node -r tsconfig-paths/register ./src/app.ts

將 babel.config.js 中的別名添加到項目后,問題得到解決。 讀這個

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM