2016-11-06 122 views
1

我正在尝试以最正确的方式导入节点模块。我想行:使用类型和NPM在TypeScript中安装节点模块

import * as pg from "pg"

工作。但现在它提高了:

Cannot find module 'pg' error

我希望我缺少一些简单的东西。


我的失败策略:

  1. npm install pg --save
  2. typings install pg --save
  3. 在tsconfig.json "files": [ "./typings/index.d.ts",

如果您对我的方法有任何建议,请告诉我。

+0

打字稿哪个版本您使用的导入? –

+0

我在编译或运行时引发这个错误? – martin

+1

如果您使用的是TypeScript 2,这可能很有趣:http://stackoverflow.com/a/38444504/5115768 – lenny

回答

1

试试这个

npm install @types/pg 

然后继续前进,它

import * as pg from "pg" 
相关问题