1

I am trying to import a Node module in the most correct way possible. I would like the line:

import * as pg from "pg"

to work. But right now it raises a:

Cannot find module 'pg' error.

I'm hoping I am missing something simple.


My failing strategy:

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

Let me know if you have any advice for my approach.

4
  • Which version of typescript are you using? Commented Nov 6, 2016 at 15:08
  • I raises this error on compilation or in runtime? Commented Nov 6, 2016 at 15:10
  • 1
    if you are using TypeScript 2, this might be interesting: stackoverflow.com/a/38444504/5115768 Commented Nov 6, 2016 at 15:10
  • And you are sure that step 2 went well? Often the command is typings install dt~pg --global. Other than that it looks like you are on the right track to me. Commented Nov 6, 2016 at 15:31

1 Answer 1

1

Try this

npm install @types/pg

Then go ahead and import it

import * as pg from "pg"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.