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.
You probably need the node.js typings, there's no (easy) way around it unfortunately. See https://github.com/TypeStrong/ts-node/issues/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.
Ah okay, I didn't realize. Sorry, I'm new to TS.
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.
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).
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!
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.
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 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?
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.
Hope for the solution. Thanks.
@Jack-Works What exactly do you hope for? You can install the node.js typings to have it working.
Install @types/node locally? That's strange... I think I may not want to install it everywhere since I may start it everywhere...
On Tue, 18 Jul 2017, 09:20 Blake Embrey, [email protected] wrote:
@Jack-Works https://github.com/jack-works What exactly do you hope for? You can install the node.js typings to have it working.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/TypeStrong/ts-node/issues/351#issuecomment-315930282, or mute the thread https://github.com/notifications/unsubscribe-auth/AFJBf_FgM1Jz5AGdy0IAdv6aZz1_RXRcks5sPAhHgaJpZM4N0YZF .
See my comment in https://github.com/TypeStrong/ts-node/issues/351#issuecomment-307179726. 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.
This should have been marked as fixed with https://github.com/TypeStrong/ts-node/pull/404
Still getting this error. npm install -g @types/node does not work. It must be installed locally.
Global attempt (failed): :-1:
sudo npm install -g @types/node
+ @types/[email protected]
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 :+1:
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/[email protected]
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
Having the same issue on Ubuntu 17.04
ts-node v3.3.0 node v8.5.0 typescript v2.5.2
It hasn't been released yet. It will be released with 4.0. Until then, please install the node.js typings.
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 (
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 did you figure out your issue? I'm also getting:
[eval].ts:1:1 - error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided.