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)
- SWC: unknown field `noInterop`, expected `resolveFully` HOT 17
- Export `ts-node/esm-register` to use with `--import` HOT 1
- tsconfig not found when extends scope with ts-node>10.0 and typescript@>=5.3.0-dev HOT 12
- v11 beta HOT 7
- Allow replacing symbols
- ts-node fails to look for path params
- not even the most simple use-case HOT 3
- console.log('hi'); fails in REPL with "module": "esnext" HOT 1
- UnhandledPromiseRejection: ts-node-esm does not display type checking results HOT 6
- ts-node doesn't run ESM modules as expected, either refusing`import` statements in ts file or not being able to run `.ts` files HOT 6
- In REPL, can't access the previous line's return value via `_`
- Error when using ts-node with tsonfig/bases and typescript 5.3.2 HOT 3
- "TypeError: require(...) is not a function" in ts-node dependecy
- extends of tsconfig.json doesn't work when it reference to other package HOT 2
- add --env-file environment variable similar to node v:20.6.0 HOT 9
- ERR_UNKNOWN_FILE_EXTENSION since Node.js 18.19.0 (works fine with 18.18.2) HOT 17
- Support clearing the local context with .clear when starting programmatically
- In #!/bin/bash clear apt update apt upgrade apt install figlet -y figlet Basic Installation apt install toilet -y apt install cowsay -y apt install nano -y apt install ruby -y gem install lolcat figlet -f big Done !!! | lolcat echo echo -e "\e[1m Now Run \e[32mbash t-ban.sh\e[0m...!!!" echo echo -e "\e[1m\e[32m Developed by :\e[33m Sutariya Parixit (8h4i)" echo echo( there are Issu for In title The Over view and synonyms Not Seen in his real formet
- ts-node is unable to resolve tsconfig files in Yarn workspace HOT 2
- ESM: Cannot find module './index.js' and requiring "imaginaryUncacheableRequireResolveScript" HOT 1
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.