简体   繁体   中英

Where do I find Traceur (ES6 Transpiler) runtime?

I am excited about ES6 and would like warm up with it using the Traceur compiler. Here's a simple classe example:

require('traceur-runtime');

class Person {

    constructor(name) {
        this.name = name;
    }

    greet() {
        return "Hello, I am " + this.name;
    }
}

var p1 = new Person("Luca");
p1.greet();

After transpiling and trying to run the example (in node), I get the following error:

Error: Cannot find module 'traceur-runtime'

Is the runtime included in the npm installation of traceur? If yes, where is it and how do I need to include it? I cannot run the code without including the runtime...

You need to install traceur-runtime via npm:

npm install traceur-runtime

And it should work. Your example works for me, at least. I compiled:

traceur --script test.js --out out/test.js

And ran:

node out/test.js

Alternatively

You can also just install traceur:

npm install traceur

And then require it:

require('traceur');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM