ts-node: Unable to use REPL on Windows or OS X.

For some reason I can’t get the REPL to work at all. Same result in both OS X and Windows.

Reproduction steps:

$ npm i -g typescript ts-node
$ ts-node
> console.log('hi');
Unable to compile TypeScript
[eval].ts (0,1): Cannot find name 'exports'. (2304)
[eval].ts (0,11): Cannot find name 'module'. (2304)

Node versions tried: v8.1.0, v7.10.0, v5.12.0

Version of ts-node installed: v3.0.6 (latest)


Edit: Tried installing different versions of ts-node. Looks like the REPL breaks in v3.0.5 but works in v3.0.4 and earlier.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 6
  • Comments: 19 (8 by maintainers)

Most upvoted comments

I see. I’ll try to get a fix in the next few days for this, I think it’s (relatively) easy to work around. I didn’t consider the case where someone wouldn’t have the types installed being an issue 😄

To make it work today, you probably need a tsconfig.json file and @types/node installed locally (no -g, TypeScript would be looking up the types relative to your tsconfig.json file).

Still getting this error. npm install -g @types/node does not work. It must be installed locally.

Global attempt (failed): 👎

sudo npm install -g @types/node
+ @types/node@8.0.28
updated 1 package in 0.683s


ts-node
> var a: number = 42;
Thrown: ⨯ Unable to compile TypeScript
[eval].ts: Cannot find name 'exports'. (2304)
[eval].ts (0,11): Cannot find name 'module'. (2304)

Local attempt success 👍

npm install @types/node
npm WARN saveError ENOENT: no such file or directory, open '/tmp/bleh/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/tmp/bleh/package.json'
npm WARN bleh No description
npm WARN bleh No repository field.
npm WARN bleh No README data
npm WARN bleh No license field.

+ @types/node@8.0.28
added 1 package in 0.713s

ts-node
> var a:number = 42;
{}

I would think this bug should remain open. REPL shouldn’t require local install. And if it does, it should error out gracefully if the dependency isn’t there.

ts-node --version
ts-node v3.3.0
node v8.5.0
typescript v2.5.2

Just verified, you only need to npm install @types/node in your working directory to get started for now. Though you’ll probably want a tsconfig.json eventually for other configuration. I’ll update this issue when I have a fix to avoid needing the typings all together.