错误TS2307:找不到模块'app'

时间:2016-10-26 21:13:58

标签: node.js express angular typescript

我想在节点端使用typescript。我有一个非常简单的服务器。我的服务器文件夹中的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文件,其中包含快速相关配置,然后我有server.ts文件,它从app.ts导入app模块,它有代码来创建和启动节点服务器。 但是我收到了以下错误:

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

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

以下是我导入模块的方法:

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

谢谢!

1 个答案:

答案 0 :(得分:1)

从项目加载文件包括路径。使用:

import * as app from './app';

使用from 'app',你说你的项目中安装了一个名为app的模块。如果是这种情况,您需要安装该模块的类型或自己创建。

相关问题