错误TS2307:无法find模块“应用程序”

我想在节点端使用打字稿。 我有一个非常简单的服务器。 我的服务器文件夹里面的tsconfig.file如下:

{ "compilerOptions": { "module": "commonjs", "target": "es5", "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "outDir": "../dist/serverBuild", "typeRoots": [ "../node_modules/@types" ] }, "exclude": [ "../node_modules" ] } 

我有一个app.ts文件,其中有明确的相关configuration,然后我有server.ts文件,这是从app.ts导入应用程序模块,它有创build和启动节点服务器的代码。 但是我得到以下错误:

TSError:⨯无法编译TypeScript server.ts(11,22):找不到模块'app'。 (2307)

其他模块,我在我的server.ts文件中导入像http模块不会抛出任何这样的错误。 我在这里做错了什么。

以下是我如何导入模块:

 import * as http from "http"; import * as app from "app"; 

谢谢!

从你的项目加载文件包括path。 使用:

 import * as app from './app'; 

通过使用from 'app'你说在你的项目中有一个名为app的模块。 如果是这种情况,您需要安装该模块的types或自己创build。