Iris
Iris

Reputation: 1476

I can't import node_modules from typescript in node.js

I have one problem. I'm trying to import node_modules in typescript but I'm getting an error

"[ts] Cannot find module 'path'."

This is my code :

import path from 'path';

Upvotes: 1

Views: 3830

Answers (2)

kimamula
kimamula

Reputation: 12649

You have to install @types/node (you may want to add --save-dev or --save).

$ npm install @types/node

Then, in your code,

import * as path from 'path';

Upvotes: 5

Shahar Hadas
Shahar Hadas

Reputation: 2827

Try the following:

import * as path from 'path';

Upvotes: 0

Related Questions