我试图获取此代码:
https://github.com/bersling/typescript-library-starter
我从中找到的工作:
https://stackoverflow.com/a/44617078/1715055
答案。
我手动编译了包并将其添加到测试包的node_modules /文件夹中。
使用--traceResolution,我得到了:
30 Loading module 'typescript-library-starter/hello-word' from 'node_modules' folder, target file type 'TypeScript'.
31 Directory '/home/ubuntu/test/ts_module/app/src/node_modules' does not exist, skipping all lookups in it.
32 Found 'package.json' at '/home/ubuntu/test/ts_module/app/node_modules/typescript-library-starter/package.json'.
33 File '/home/ubuntu/test/ts_module/app/node_modules/typescript-library-starter/hello-word.ts' does not exist.
34 File '/home/ubuntu/test/ts_module/app/node_modules/typescript-library-starter/hello-word.tsx' does not exist.
35 File '/home/ubuntu/test/ts_module/app/node_modules/typescript-library-starter/hello-word.d.ts' does not exist.
换句话说,它没有检测到package.json中的types
字段。我安装了另一个包含typings
字段的Typescript包,并且在跟踪它时正确解析:
11 Found 'package.json' at '/home/ubuntu/test/ts_module/app/node_modules/json-schema-to-typescript/package.json'.
12 'package.json' has 'typings' field 'dist/src/index.d.ts' that references '/home/ubuntu/test/ts_module/app/node_modules/json-schema-to-typescript/dist/src/index.d.ts'.
13 File '/home/ubuntu/test/ts_module/app/node_modules/json-schema-to-typescript/dist/src/index.d.ts' exist - use it as a name resolution result.
。
编辑: 我的tsc --version是2.6.1并且我尝试使用' typings'单独和两个' typings'和'类型'。