我的目录结构如下:
|
|__src
| |_components
| |
| |_A
| |_index.tsx
|
|
tsconfig.json
package.json
我想像这样导入A
:
从 'src/components/A' 导入 { A }
我的 tsconfig.json 文件如下:
{
"compilerOptions": {
"baseUrl": "",
"declaration": true,
"downlevelIteration": true,
"esModuleInterop": true,
"jsx": "react",
"lib": ["es5", "es2015", "es2016", "dom"],
"module": "esnext",
"moduleResolution": "node",
"noImplicitAny": true,
"noUnusedLocals": true,
"noImplicitReturns": true,
"outDir": "dist",
"removeComments": false,
"skipLibCheck": true,
"strict": true,
"strictFunctionTypes": false,
"strictNullChecks": false,
"suppressImplicitAnyIndexErrors": true,
"target": "es5",
"typeRoots": ["./node_modules/@types"],
"types": ["node", "jest"],
"paths": {
"*": ["./node_modules/@types/*", "./types/*"]
}
},
"include": ["src/**/*.ts", "src/**/*.tsx"],
"exclude": ["./node_modules", "./dist", "src/**/*.test.ts", "src/**/*.test.tsx"]
}
但是导入不起作用,我得到了以下错误:
找不到模块“src/components/A”
中的尾随
` 非常重要! - handlerimport { A } from 'components/A/index'
? - Neil Gaetano Lindberg"moduleNameMapper": { "^src/(.*)$": [ "/src/$1"
],
}
- undefined