Actually, it's even easier - the Typescript compiler has an option for converting import statements to require statements (and export statements to module.exports) built in. You can simply put "module": "CommonJS" into your tsconfig.json file, and you can still stick to using just the Typescript compiler to generate ES6 code that will run in Node.js.
I like being able to polyfill though, which was more the point of this. Writing clean async/await code and then compiling to an older version of node is great. I have to support node 6 in my day job.
Setting module to CommonJs will compile async await to ES6, the same way Babel does.
Buy this guide is pretty useful considering we can add more functionality with Babel and gulp later on.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Actually, it's even easier - the Typescript compiler has an option for converting
import
statements torequire
statements (andexport
statements tomodule.exports
) built in. You can simply put"module": "CommonJS"
into yourtsconfig.json
file, and you can still stick to using just the Typescript compiler to generate ES6 code that will run in Node.js.That's awesome, I really didn't know that!
I like being able to polyfill though, which was more the point of this. Writing clean async/await code and then compiling to an older version of node is great. I have to support node 6 in my day job.
Setting module to CommonJs will compile async await to ES6, the same way Babel does.
Buy this guide is pretty useful considering we can add more functionality with Babel and gulp later on.