Comments (11)
What TypeScript version are you using it with? Can you post a reproducible test case?
That's a JavaScript error, so I think you're using this with a JavaScript file instead of a TypeScript file. Can you confirm that? Otherwise, I'd say it's the target output in tsconfig.json
that's the issue (it's not supported with your node version).
from ts-node.
@blakeembrey This is a problem with my mocha tests. As per some instructions I found somewhere, I added require('ts-node/register')
at the top of my gulpfile, and all of my typescript code/tests works nicely with a simple .pipe(mocha());
. (Including ones with language features like async/away and yield.) However, if I use destructuring in my typescript code, then the tests will fail with the error above.
And, yes I'm using node 4.2.1 which doesn't support destructuring by default yet.
from ts-node.
Are the tests written in TypeScript or JavaScript. What about your tsconfig.json
file - I guess you're targeting ES6? Is ts-node
executing? I believe async/await and yield are all standard in node v4.
I'm not sure there's a solution if node doesn't support destructuring but does support things like async
since TypeScript does not support as fine-grained tuning. If that's the case though, this is something to bring up with the TypeScript team (who I've seen discuss fine grained tuning in the past, so this just be an extra use-case on that).
from ts-node.
Following up quickly, check out https://kangax.github.io/compat-table/es6/#test-destructuring. Looks like this is an issue, TypeScript will only compile "all" ES6 for us but node can't handle destructuring (maybe other things).
from ts-node.
My tests are written in typescript. As far as I can tell, ts-node/register
must be doing some kind of es5 transpilation because I'm pretty sure that node 4.2.1 doesn't support es6 imports yet (I also don't think that it supports async/await yet see: https://nodejs.org/en/docs/es6/), and I'm using those in my code & in my tests.
By the way, thanks for your work on the typings module, it's been a better solution that tsd for me so far.
from ts-node.
My tests are written in typescript
You're right, I had to investigate and found that node currently doesn't support destructuring. I wish there wasn't something we could do here since that's a trivial issue for the compiler to handle, but TypeScript doesn't support feature flags. An existing discussion can be found at microsoft/TypeScript#4692, but it looks like it might have been derailed - I'll check in and see what's happening since this is a pretty helpful use-case.
By the way, thanks for your work on the typings module
Thanks so much! I'm glad it works for you, I haven't had a lot of feedback yet so it's hard to tell if I'm confusing people or if it's communicating the message correctly. There's a need for more corrected typings, so if you get a chance 😄
from ts-node.
Yeah, I want to add some more typings because I'm having to install a lot of definitelytyped .d.ts
files as ambient dependencies when I really want to save them as dev dependencies (a dev-ambient dependency might also help for things like mocha). I just want to get a better handle on it before I start making any pull requests. If you have, or were to make, a simple wiki page on how to create a typing definition project, I'd definitely start converting them.
I remember having a discussion when definitelytyped first came out that it would be better to have had each typing as a separate repo, but that met with a lot of resistance, so I'm really glad that you went in that direction...especially with the 1,385 folders that definitelytyped now handles.
from ts-node.
a dev-ambient dependency might also help for things like mocha
Haha, yeah, you're probably correct. I originally had that parity, but removed it from typings before release. I can simply add it back, ambient dependencies aren't included with any installation anyway - they are just for environment "reference" here.
If you have, or were to make, a simple wiki page on how to create a typing definition project
I'll look at adding one for you (or to the FAQ in the README), but it's mostly straightforward - just moving everything inside the ambient declare module "x"
to outside and creating a repo for it. There's a lot in https://github.com/typings, though I wrote most of them from scratch. If you ever hit an issue, you can always open a discussion.
You can always create the files/repos under your own user too, then just add them to the registry 😄 Supporting DefinitelyTyped as ambient is a nice use-case too, which I've avoided documenting but perhaps I should if people are discovering it anyway. It would probably solve all the TSD woes.
from ts-node.
I'm going to reopen this for visibility or until it's fixed upstream in TypeScript
from ts-node.
FYI - If you are using mocha you can enable destructuring and default parameters using
mocha --harmony --harmony-destructuring --harmony_default_parameters
from ts-node.
Closing as answered, as far as I can tell it won't ever be fixed in TypeScript. Thankfully, ES6 works with node 6.
from ts-node.
Related Issues (20)
- calling `repl.start()` causes a doubling of stdin/stdout
- ts-node cannot run mixed ESM/CJS project HOT 2
- Cryptic error on invalid tsconfig.json, e.g. if attempting to extend nonexistent tsconfig file
- ts-node doesn't resolve extended tsconfigs if they originate from the export fields of packages
- [Error [ERR_REQUIRE_ESM]: require() of ES Module /.../node_modules/ts-node/esm.mjs not supported. HOT 1
- [DEP0180] DeprecationWarning: fs.Stats constructor is deprecated when using node 22
- Setting emitAssertForImportAttributes no longer works in Node.js 22 with latest swc HOT 1
- Last release was 6 months ago... is the project dead? HOT 9
- How funny a ts-node that does not read .ts file hahahha HOT 2
- Compile not outputing expected format
- TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" HOT 10
- ERR_REQUIRE_ESM: Require of ES Module in CommonJS Context (ts-node, svgdom)
- Transpile-only doesn't work without tsconfig.json
- Debugging + cluster.fork in vscode results in an error Unknown or unexpected option:--inspect-port HOT 3
- Gulp: ERR_UNKNOWN_FILE_EXTENSION HOT 3
- Using register() with typecheck: false still fails with a type error in test run
- Compile time errors being suppressed when using esm
- Importing modules without named exports fails when using ts-node/esm
- this Project is already dead , please friends use tsx or swc-node to instead it
- Wrong TS2345 error message in screenshot on website
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ts-node.