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, notifications@github.com 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.
throw new TSError(formatDiagnostics(diagnosticList, cwd, ts, lineOffset))
^
TSError: Γ¿» Unable to compile TypeScript
srctestApp.spec.tsx (19,33): Parameter 'obj' implicitly has an 'any' type. (7006)
srctestApp.spec.tsx (21,34): Parameter 'obj' implicitly has an 'any' type. (7006)
srctestApp.spec.tsx (21,237): Property 'default' does not exist on type '{}'. (2339)
srctestApp.spec.tsx (34,24): Left side of comma operator is unused and has no side effects. (2695)
srctestApp.spec.tsx (40,10): Left side of comma operator is unused and has no side effects. (2695)
srctestApp.spec.tsx: Cannot compile namespaces when the '--isolatedModules' flag is provided. (1208)
at getOutput (D:AssetWiseGridAssetWiseConnectAssetWiseCONNECTsrcClientassetwiseconnectnode_modulests-nodesrcindex.ts:330:15)
at Object.compile (D:AssetWiseGridAssetWiseConnectAssetWiseCONNECTsrcClientassetwiseconnectnode_modulests-nodesrcindex.ts:518:11)
at Module.m._compile (D:AssetWiseGridAssetWiseConnectAssetWiseCONNECTsrcClientassetwiseconnectnode_modulests-nodesrcindex.ts:403:43)
at loader (D:AssetWiseGridAssetWiseConnectAssetWiseCONNECTsrcClientassetwiseconnectnode_modulesbabel-registerlibnode.js:144:5)
at require.extensions.(anonymous function) (D:AssetWiseGridAssetWiseConnectAssetWiseCONNECTsrcClientassetwiseconnectnode_modulesbabel-registerlibnode.js:154:7)
at Object.require.extensions.(anonymous function) [as .tsx] (D:AssetWiseGridAssetWiseConnectAssetWiseCONNECTsrcClientassetwiseconnectnode_modulests-nodesrcindex.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:AssetWiseGridAssetWiseConnectAssetWiseCONNECTsrcClientassetwiseconnectnode_modulesmochalibmocha.js:253:27
at Array.forEach (
at Mocha.loadFiles (D:AssetWiseGridAssetWiseConnectAssetWiseCONNECTsrcClientassetwiseconnectnode_modulesmochalibmocha.js:250:14)
at Mocha.run (D:AssetWiseGridAssetWiseConnectAssetWiseCONNECTsrcClientassetwiseconnectnode_modulesmochalibmocha.js:577:10)
at Object.
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 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.
Most helpful comment
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.jsonfile and@types/nodeinstalled locally (no-g, TypeScript would be looking up the types relative to yourtsconfig.jsonfile).