我有一个使用TypeScript的简单示例项目:https : //github.com/unindented/ts-webpack-example
运行tsc -p .
(tsc
版本1.8.10)会引发以下情况:
app/index.ts(1,21): error TS2307: Cannot find module 'components/counter'.
components/button/index.ts(2,22): error TS2307: Cannot find module 'shared/backbone_base_view'.
components/button/index.ts(3,25): error TS2307: Cannot find module 'shared/backbone_with_default_render'.
components/counter/index.ts(2,22): error TS2307: Cannot find module 'shared/backbone_base_view'.
components/counter/index.ts(3,25): error TS2307: Cannot find module 'shared/backbone_with_default_render'.
components/counter/index.ts(4,27): error TS2307: Cannot find module 'shared/backbone_with_subviews'.
components/counter/index.ts(5,20): error TS2307: Cannot find module 'components/button'.
它抱怨所有本地文件的导入,如下所示:
import Counter from 'components/counter';
如果我将其更改为相对路径,则可以使用,但我不想这样做,因为在移动文件时,这会使我的生活更加困难:
import Counter from '../components/counter';
该vscode
代码库不使用相对路径,但一切工作正常他们,所以我必须失去在我的项目的东西:https://github.com/Microsoft/vscode/blob/0e81224179fbb8f6fda18ca7362d8500a263cfef/src/vs/languages/typescript/common /typescript.ts#L7-L14
您可以查看我的GitHub存储库,但是如果有帮助的话,这里是tsconfig.json
我正在使用的文件:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"noImplicitAny": false,
"removeComments": false,
"preserveConstEnums": true,
"sourceMap": true,
"outDir": "dist"
},
"exclude": [
"dist",
"node_modules"
]
}
有趣的是,通过webpack
使用ts-loader
可以很好地构建项目,所以我猜这只是一个配置问题...
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句