-1
我src/shared/components/A.tsx
,做import B from 'components/B'
(src/shared/components/B.tsx
)打字稿使用ES6模块
打字稿给我一个错误有一个文件“找不到模块
cannot find module 'components/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
]
}
}
我从https://www.typescriptlang.org/docs/handbook/tsconfig-json.html理解是,它会试图找到./components/B
第一,它不不存在,然后进入<baseUrl>/src/shared/components/B
,这是文件存在的位置,所以我不知道为什么我仍然看到一个错误。
出于好奇 - 如果您将'.jsx'文件重命名为'.js'文件,这是否工作?如果你用'.jsx'作为后缀显式导入,那么它是否解决了它? –
它工作之前,我移植到打字稿,如果我改变文件扩展名打字稿不会抛出错误的文件。但是,模块B在代码中存在错误,导致它无法编译......打字稿是否尝试编译导入到文件中的模块? – PDN