繁体   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