Code Monkey home page Code Monkey logo

Comments (3)

aMarCruz avatar aMarCruz commented on August 18, 2024

@philmaker1 , please give us more details, mainly the tag that is generating the error.
any task runner?

from compiler.

GianlucaGuarini avatar GianlucaGuarini commented on August 18, 2024

@philmaker1 with no infos we can help you on this issue. I will be glad to reopen it whenever you will find a bit of time for us

from compiler.

speckins avatar speckins commented on August 18, 2024

@philmaker1 Were you reading the file with the 'fs' module? You may have inadvertently been passing a Buffer into riot.compile(). If you read the documentation for the fs.readFile callback, you'll see how the type of the second parameter changes depending on how readFile() is called.

test.tag:

<test>
    <h2>Hello, World!</h2>

    <script>
        this.f = function() {
        };
        this.v = opts.value;
    </script>
</test>

riot.js:

var riot = require('riot');
var fs = require('fs');

fs.readFile('test.tag', function(err, tag) {
    if (err) {
        console.error(err);
    } else {
        console.log(riot.compile(tag));
    }
});

Error

$ node riot.js
./node_modules/riot-compiler/lib/compiler.js:925
    .replace(CUST_TAG, function (_, indent, tagName, attribs, body, body2) {
     ^

TypeError: cleanSource(...).replace is not a function
    at Object.compile (./node_modules/riot-compiler/lib/compiler.js:925:6)
    at ./riot.js:8:20
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:415:3)});

Solution 1:

// Specify the encoding and tag will be a string
fs.readFile('test.tag', 'utf8', function(err, tag) {

Solution 2:

// Call toString() on the buffer
console.log(riot.compile(tag.toString()));

Either way, no more error

$ node riot.js
riot.tag2('test', '<h2>Hello, World!</h2>', '', '', function(opts) {
        this.f = function() {
        };
        this.v = opts.value;
});

from compiler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.