Reactjs Typescript";找不到模块<;模块>&引用;使用ES6模块时出错
我在Reactjs Typescript";找不到模块<;模块>&引用;使用ES6模块时出错,reactjs,typescript,Reactjs,Typescript,我在src/shared/components/a.tsx中有一个文件,它从'components/B'导入B(src/shared/components/B.tsx) Typescript给我一个错误找不到模块“组件/B” 这是我的tsconfig.json文件,它位于根目录中: { "compilerOptions": { "outDir": "./dist/", "sourceMap": true, "module": "es6", "t
src/shared/components/a.tsx
中有一个文件,它从'components/B'导入B(src/shared/components/B.tsx
)
Typescript给我一个错误找不到模块“组件/B”
这是我的tsconfig.json
文件,它位于根目录中:
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"module": "es6",
"target": "es6",
"jsx": "react",
"allowJs": true,
"moduleResolution": "node"
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules"
],
"baseUrl": ".",
"paths": {
"*": [
"*",
"src/shared/*" //this doesn't seem to work
]
}
}
我的理解是,它将首先尝试查找不存在的
/components/B
,然后进入文件存在的/src/shared/components/B
,因此我不确定为什么仍然看到错误。这很愚蠢,路径
/基本URL
属于编译器选项
内,这是出于好奇-如果将.jsx
文件重命名为.js
文件,是否有效?如果以.jsx
作为后缀显式导入,是否可以解决此问题?它在我移植到typescript之前工作,如果我更改文件扩展名,typescript不会在文件中抛出错误。但是,模块B的代码中有错误,这将阻止它编译。。。typescript是否尝试编译导入到文件中的模块?