New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use REPL on Windows or OS X. #351

Closed
chevex opened this Issue Jun 8, 2017 · 18 comments

Comments

Projects
None yet
7 participants
@chevex

chevex commented Jun 8, 2017

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.

@chevex chevex changed the title from Unable to use repl on Windows or OS X. to Unable to use REPL on Windows or OS X. Jun 8, 2017

@blakeembrey

This comment has been minimized.

Show comment
Hide comment
@blakeembrey

blakeembrey Jun 8, 2017

Member

You probably need the node.js typings, there's no (easy) way around it unfortunately. See #331 for more info. Feel free to complain to TypeScript since that would be the ideal solution, but I had to hack around it. I may also be able to inject exports before TypeScript eval to avoid it, but these hacks on hacks are just getting a bit long.

Member

blakeembrey commented Jun 8, 2017

You probably need the node.js typings, there's no (easy) way around it unfortunately. See #331 for more info. Feel free to complain to TypeScript since that would be the ideal solution, but I had to hack around it. I may also be able to inject exports before TypeScript eval to avoid it, but these hacks on hacks are just getting a bit long.

@chevex

This comment has been minimized.

Show comment
Hide comment
@chevex

chevex Jun 8, 2017

Ah okay, I didn't realize. Sorry, I'm new to TS.

chevex commented Jun 8, 2017

Ah okay, I didn't realize. Sorry, I'm new to TS.

@chevex

This comment has been minimized.

Show comment
Hide comment
@chevex

chevex Jun 8, 2017

Totally fine if you're too busy to help a newbie but can you point me to info on how I install this "node.js typings"? I have ts-node installed globally. So far based on this answer I've tried npm install -g @types/node but that doesn't seem to fix anything. Even just a link to learn about typings better so I have a good starting point would be much appreciated.

Edit: Have since also tried installing typings module and executing typings install env~node --save --global and still no luck when running the REPL.

chevex commented Jun 8, 2017

Totally fine if you're too busy to help a newbie but can you point me to info on how I install this "node.js typings"? I have ts-node installed globally. So far based on this answer I've tried npm install -g @types/node but that doesn't seem to fix anything. Even just a link to learn about typings better so I have a good starting point would be much appreciated.

Edit: Have since also tried installing typings module and executing typings install env~node --save --global and still no luck when running the REPL.

@blakeembrey

This comment has been minimized.

Show comment
Hide comment
@blakeembrey

blakeembrey Jun 8, 2017

Member

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).

Member

blakeembrey commented Jun 8, 2017

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).

@chevex

This comment has been minimized.

Show comment
Hide comment
@chevex

chevex Jun 8, 2017

Thanks so much!

I guess my thinking was that a REPL would be the perfect place to test out basic TypeScript concepts but it's more complicated than I realized apparently thanks to changes in TypeScript. Thanks for the quick replies!

chevex commented Jun 8, 2017

Thanks so much!

I guess my thinking was that a REPL would be the perfect place to test out basic TypeScript concepts but it's more complicated than I realized apparently thanks to changes in TypeScript. Thanks for the quick replies!

@blakeembrey

This comment has been minimized.

Show comment
Hide comment
@blakeembrey

blakeembrey Jun 8, 2017

Member

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.

Member

blakeembrey commented Jun 8, 2017

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.

@dinvlad

This comment has been minimized.

Show comment
Hide comment
@dinvlad

dinvlad Jun 22, 2017

Strange - @types/node is already installed locally but I still get that (the error message is slightly different though: [eval].ts (0,18): Property 'exports' does not exist on type '{ id: string; }'. (2339))

dinvlad commented Jun 22, 2017

Strange - @types/node is already installed locally but I still get that (the error message is slightly different though: [eval].ts (0,18): Property 'exports' does not exist on type '{ id: string; }'. (2339))

@blakeembrey

This comment has been minimized.

Show comment
Hide comment
@blakeembrey

blakeembrey Jun 23, 2017

Member

@dinvlad Can you check the type of module? Maybe it's not using @types/node as expected? Do you have types defined in your tsconfig.json file?

Member

blakeembrey commented Jun 23, 2017

@dinvlad Can you check the type of module? Maybe it's not using @types/node as expected? Do you have types defined in your tsconfig.json file?

@dinvlad

This comment has been minimized.

Show comment
Hide comment
@dinvlad

dinvlad Jun 23, 2017

Ok, sorry that may have been a separate issue. I've had an src/typings.d.ts file with this content:

/* SystemJS module definition */
declare var module: {
  id: string;
};

This file was created by Angular CLI and obviously could interfere with module resolution in ts-node. I've created a new Angular project, which then generated the following file:

/* SystemJS module definition */
declare var module: NodeModule;
interface NodeModule {
  id: string;
}

Now, ts-node works without an error. So it appears that the issue came from an older version of Angular CLI.

dinvlad commented Jun 23, 2017

Ok, sorry that may have been a separate issue. I've had an src/typings.d.ts file with this content:

/* SystemJS module definition */
declare var module: {
  id: string;
};

This file was created by Angular CLI and obviously could interfere with module resolution in ts-node. I've created a new Angular project, which then generated the following file:

/* SystemJS module definition */
declare var module: NodeModule;
interface NodeModule {
  id: string;
}

Now, ts-node works without an error. So it appears that the issue came from an older version of Angular CLI.

@Jack-Works

This comment has been minimized.

Show comment
Hide comment
@Jack-Works

Jack-Works Jul 17, 2017

Hope for the solution. Thanks.

Jack-Works commented Jul 17, 2017

Hope for the solution. Thanks.

@blakeembrey

This comment has been minimized.

Show comment
Hide comment
@blakeembrey

blakeembrey Jul 18, 2017

Member

@Jack-Works What exactly do you hope for? You can install the node.js typings to have it working.

Member

blakeembrey commented Jul 18, 2017

@Jack-Works What exactly do you hope for? You can install the node.js typings to have it working.

@Jack-Works

This comment has been minimized.

Show comment
Hide comment
@Jack-Works

Jack-Works Jul 18, 2017

Jack-Works commented Jul 18, 2017

@blakeembrey

This comment has been minimized.

Show comment
Hide comment
@blakeembrey

blakeembrey Jul 18, 2017

Member

See my comment in #351 (comment). I will update it when I have time. You're welcome to make a PR if you need this ASAP, but I don't think this is hugely unexpected since it is called ts-node and likely needs node.js typings to work anyway.

Member

blakeembrey commented Jul 18, 2017

See my comment in #351 (comment). I will update it when I have time. You're welcome to make a PR if you need this ASAP, but I don't think this is hugely unexpected since it is called ts-node and likely needs node.js typings to work anyway.

@blakeembrey

This comment has been minimized.

Show comment
Hide comment
@blakeembrey

blakeembrey Aug 24, 2017

Member

This should have been marked as fixed with #404

Member

blakeembrey commented Aug 24, 2017

This should have been marked as fixed with #404

@EvanCarroll

This comment has been minimized.

Show comment
Hide comment
@EvanCarroll

EvanCarroll Sep 13, 2017

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

EvanCarroll commented Sep 13, 2017

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

@Olian04

This comment has been minimized.

Show comment
Hide comment
@Olian04

Olian04 Sep 14, 2017

Having the same issue on Ubuntu 17.04

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

Olian04 commented Sep 14, 2017

Having the same issue on Ubuntu 17.04

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

@blakeembrey

This comment has been minimized.

Show comment
Hide comment
@blakeembrey

blakeembrey Sep 15, 2017

Member

It hasn't been released yet. It will be released with 4.0. Until then, please install the node.js typings.

Member

blakeembrey commented Sep 15, 2017

It hasn't been released yet. It will be released with 4.0. Until then, please install the node.js typings.

@dev-end

This comment has been minimized.

Show comment
Hide comment
@dev-end

dev-end May 29, 2018

Is my issue same? I am unable to resolve it even after installing @types/node locally.

D:....................................T\src\Client...............\node_modules\ts-node\src\index.ts:330

    throw new TSError(formatDiagnostics(diagnosticList, cwd, ts, lineOffset))
          ^

TSError: Γ¿» Unable to compile TypeScript
src\test\App.spec.tsx (19,33): Parameter 'obj' implicitly has an 'any' type. (7006)
src\test\App.spec.tsx (21,34): Parameter 'obj' implicitly has an 'any' type. (7006)
src\test\App.spec.tsx (21,237): Property 'default' does not exist on type '{}'. (2339)
src\test\App.spec.tsx (34,24): Left side of comma operator is unused and has no side effects. (2695)
src\test\App.spec.tsx (40,10): Left side of comma operator is unused and has no side effects. (2695)
src\test\App.spec.tsx: Cannot compile namespaces when the '--isolatedModules' flag is provided. (1208)
at getOutput (D:\AssetWiseGrid\AssetWiseConnect\AssetWiseCONNECT\src\Client\assetwiseconnect\node_modules\ts-node\src\index.ts:330:15)
at Object.compile (D:\AssetWiseGrid\AssetWiseConnect\AssetWiseCONNECT\src\Client\assetwiseconnect\node_modules\ts-node\src\index.ts:518:11)
at Module.m._compile (D:\AssetWiseGrid\AssetWiseConnect\AssetWiseCONNECT\src\Client\assetwiseconnect\node_modules\ts-node\src\index.ts:403:43)
at loader (D:\AssetWiseGrid\AssetWiseConnect\AssetWiseCONNECT\src\Client\assetwiseconnect\node_modules\babel-register\lib\node.js:144:5)
at require.extensions.(anonymous function) (D:\AssetWiseGrid\AssetWiseConnect\AssetWiseCONNECT\src\Client\assetwiseconnect\node_modules\babel-register\lib\node.js:154:7)
at Object.require.extensions.(anonymous function) [as .tsx] (D:\AssetWiseGrid\AssetWiseConnect\AssetWiseCONNECT\src\Client\assetwiseconnect\node_modules\ts-node\src\index.ts:406:12)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at D:\AssetWiseGrid\AssetWiseConnect\AssetWiseCONNECT\src\Client\assetwiseconnect\node_modules\mocha\lib\mocha.js:253:27
at Array.forEach ()
at Mocha.loadFiles (D:\AssetWiseGrid\AssetWiseConnect\AssetWiseCONNECT\src\Client\assetwiseconnect\node_modules\mocha\lib\mocha.js:250:14)
at Mocha.run (D:\AssetWiseGrid\AssetWiseConnect\AssetWiseCONNECT\src\Client\assetwiseconnect\node_modules\mocha\lib\mocha.js:577:10)
at Object. (D:\AssetWiseGrid\AssetWiseConnect\AssetWiseCONNECT\src\Client\assetwiseconnect\node_modules\mocha\bin_mocha:591:18)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Function.Module.runMain (module.js:684:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3

package.json
"scripts": {
"start": "react-scripts-ts start",
"build": "react-scripts-ts build",
"test": "NODE_ENV=development mocha src/test/App.spec.tsx -r ts-node/register -r ts-loader --compilers js:babel-core/register -r ignore-styles --watch-extensions tsx,ts",
"eject": "react-scripts-ts eject"
},

dev-end commented May 29, 2018

Is my issue same? I am unable to resolve it even after installing @types/node locally.

D:....................................T\src\Client...............\node_modules\ts-node\src\index.ts:330

    throw new TSError(formatDiagnostics(diagnosticList, cwd, ts, lineOffset))
          ^

TSError: Γ¿» Unable to compile TypeScript
src\test\App.spec.tsx (19,33): Parameter 'obj' implicitly has an 'any' type. (7006)
src\test\App.spec.tsx (21,34): Parameter 'obj' implicitly has an 'any' type. (7006)
src\test\App.spec.tsx (21,237): Property 'default' does not exist on type '{}'. (2339)
src\test\App.spec.tsx (34,24): Left side of comma operator is unused and has no side effects. (2695)
src\test\App.spec.tsx (40,10): Left side of comma operator is unused and has no side effects. (2695)
src\test\App.spec.tsx: Cannot compile namespaces when the '--isolatedModules' flag is provided. (1208)
at getOutput (D:\AssetWiseGrid\AssetWiseConnect\AssetWiseCONNECT\src\Client\assetwiseconnect\node_modules\ts-node\src\index.ts:330:15)
at Object.compile (D:\AssetWiseGrid\AssetWiseConnect\AssetWiseCONNECT\src\Client\assetwiseconnect\node_modules\ts-node\src\index.ts:518:11)
at Module.m._compile (D:\AssetWiseGrid\AssetWiseConnect\AssetWiseCONNECT\src\Client\assetwiseconnect\node_modules\ts-node\src\index.ts:403:43)
at loader (D:\AssetWiseGrid\AssetWiseConnect\AssetWiseCONNECT\src\Client\assetwiseconnect\node_modules\babel-register\lib\node.js:144:5)
at require.extensions.(anonymous function) (D:\AssetWiseGrid\AssetWiseConnect\AssetWiseCONNECT\src\Client\assetwiseconnect\node_modules\babel-register\lib\node.js:154:7)
at Object.require.extensions.(anonymous function) [as .tsx] (D:\AssetWiseGrid\AssetWiseConnect\AssetWiseCONNECT\src\Client\assetwiseconnect\node_modules\ts-node\src\index.ts:406:12)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at D:\AssetWiseGrid\AssetWiseConnect\AssetWiseCONNECT\src\Client\assetwiseconnect\node_modules\mocha\lib\mocha.js:253:27
at Array.forEach ()
at Mocha.loadFiles (D:\AssetWiseGrid\AssetWiseConnect\AssetWiseCONNECT\src\Client\assetwiseconnect\node_modules\mocha\lib\mocha.js:250:14)
at Mocha.run (D:\AssetWiseGrid\AssetWiseConnect\AssetWiseCONNECT\src\Client\assetwiseconnect\node_modules\mocha\lib\mocha.js:577:10)
at Object. (D:\AssetWiseGrid\AssetWiseConnect\AssetWiseCONNECT\src\Client\assetwiseconnect\node_modules\mocha\bin_mocha:591:18)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Function.Module.runMain (module.js:684:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3

package.json
"scripts": {
"start": "react-scripts-ts start",
"build": "react-scripts-ts build",
"test": "NODE_ENV=development mocha src/test/App.spec.tsx -r ts-node/register -r ts-loader --compilers js:babel-core/register -r ignore-styles --watch-extensions tsx,ts",
"eject": "react-scripts-ts eject"
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment