frontend/app-core/services/ApiGateway.ts -> 我想从react-native项目导入代码的实际文件 frontend/react-native-app/services -> 上面的符号链接 frontend/react-native-app/screens/Auth/tokenStorage.ts -> 我想将其导入到 ApiGateway.ts 文件中。
使用配置成功的别名时出错。 这些文件都不存在:
2 |从“@screens/Auth/tokenStorage”导入{retrieveTokenSecurely}; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^ 3 | 4 | // 创建 axios 实例的函数 5 |导出 const createApiGateway = (baseURL: 字符串, 超时 = 10000) => { 在 ModuleResolver.resolveDependency (/Users/amit/Projects/projecttracker/frontend/react-native-app/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:112:15) 在 DependencyGraph.resolveDependency (/Users/amit/Projects/projecttracker/frontend/react-native-app/node_modules/metro/src/node-haste/DependencyGraph.js:235:43) 在/Users/amit/Projects/projecttracker/frontend/react-native-app/node_modules/metro/src/lib/transformHelpers.js:156:21 在resolveDependencies处(/Users/amit/Projects/projecttracker/frontend/react-native-app/node_modules/metro/src/DeltaBundler/buildSubgraph.js:42:25) 访问时(/Users/amit/Projects/projecttracker/frontend/react-native-app/node_modules/metro/src/DeltaBundler/buildSubgraph.js:83:30) 在 async Promise.all(索引 9) 在异步访问时(/Users/amit/Projects/projecttracker/frontend/react-native-app/node_modules/metro/src/DeltaBundler/buildSubgraph.js:92:5) 在 async Promise.all(索引 3) 在异步访问时(/Users/amit/Projects/projecttracker/frontend/react-native-app/node_modules/metro/src/DeltaBundler/buildSubgraph.js:92:5) 在 async Promise.all(索引 5)
没有别名的错误:
错误:无法从 /Users/amit/Projects/projecttracker/frontend/app-core/services/ApiGateway.ts 解析模块 ../screens/Auth/tokenStorage:
这些文件都不存在:
2 |从'../screens/Auth/tokenStorage'导入{retrieveTokenSecurely}; | ^ 3 | 4 | // 创建 axios 实例的函数 5 |导出 const createApiGateway = (baseURL: 字符串, 超时 = 10000) => { 在 ModuleResolver.resolveDependency (/Users/amit/Projects/projecttracker/frontend/react-native-app/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:112:15) 在 DependencyGraph.resolveDependency (/Users/amit/Projects/projecttracker/frontend/react-native-app/node_modules/metro/src/node-haste/DependencyGraph.js:235:43) 在/Users/amit/Projects/projecttracker/frontend/react-native-app/node_modules/metro/src/lib/transformHelpers.js:156:21 在resolveDependencies处(/Users/amit/Projects/projecttracker/frontend/react-native-app/node_modules/metro/src/DeltaBundler/buildSubgraph.js:42:25) 访问时(/Users/amit/Projects/projecttracker/frontend/react-native-app/node_modules/metro/src/DeltaBundler/buildSubgraph.js:83:30) 在 process.processTicksAndRejections (节点:内部/进程/task_queues:95:5) 在 async Promise.all(索引 9) 在异步访问时(/Users/amit/Projects/projecttracker/frontend/react-native-app/node_modules/metro/src/DeltaBundler/buildSubgraph.js:92:5) 在 async Promise.all(索引 3) 在异步访问时(/Users/amit/Projects/projecttracker/frontend/react-native-app/node_modules/metro/src/DeltaBundler/buildSubgraph.js:92:5)
我在 babel 中添加了以下内容 插件:[ [ '模块解析器', { root: ['./'], // 假设你的来源 别名:{ '@组件': './组件', '@screens': './screens', '@services': '../app-core/services', // //为生产更改此设置,将服务移动到项目文件夹 '@_services': './服务', "@constants": "./常量", “@redux”:“./redux” }, }, ], ],
&遵循 tsconfig &它工作得很好 “编译器选项”:{ "baseUrl": "./", “路径”:{ "@components/": ["./components/"], "@screens/": ["./screens/"], "@services/": ["./shared/services/"], "@_services/": ["服务/"], "@constants/": ["./constants/"], “@redux/”:[“./redux/”] }, “保留符号链接”:true }