打字稿tsconfig找不到模块和名称

时间:2019-10-31 21:46:29

标签: typescript compilation tsc tsconfig

我的项目结构:

root
├── project1
│   ├── node_modules
│   └── index.ts
├── project2
│   ├── node_modules
│   └── index.ts
└── tsconfig.json

我正在使用默认的tsconfig,希望它能够正确解析模块,但是我收到类似以下错误:

Cannot find module 'path'
Cannot find name 'require'

如果我在每个项目中使用2个不同的tsconfig进行编译,它将起作用。为什么这不能正常工作?我该怎么做才能使这项工作成功?

1 个答案:

答案 0 :(得分:0)

我猜想TypeScript编译器正在寻找tsconfig.json文件的同级node_modules文件夹。您是否还可以在项目的根目录中创建package.json并在根目录中安装要查找的@ types /文件?