Probelm: Cannot use export/import with Node.js
Solution:
-
install two packages: babel-cli and babel-preset-env and save them both as dev dependancies. npm init npm install babel-cli babel-preset-env --save-dev
-
compile: ./node_modules/.bin/babel-node main.js
export.js: the js file contains the export function main.js (compile this with babel-node): the js file contains the import function
References:
https://medium.com/@JedaiSaboteur/import-export-babel-and-node-a2e332d15673
https://medium.com/10coding/node-js-%E4%BD%BF%E7%94%A8-babel-%E5%81%9A-es6-%E9%96%8B%E7%99%BC-44b5b9e5f508
Problem:
Change the reading behavior inside module/class
for instance:
original: greet(){} <--> console.log(xxx.greet())
changed: get greet(){} <--> console.log(xxx.greet)
tsc cannot compile. error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
Solution: tsc --target es5 script.ts