durandalgulpdurandal-2.0gulp-watchgulp-less

gulp-durandal TypeError: req.toUrl is not a function


I try to implement gulp to my durandal project as explain on Durandal gulp doc

main.js file is successfully build, but when trying to click something that will open a modal dialog, it will show this error (firefox):

TypeError: req.toUrl is not a function
url = req.toUrl(nonStripName),
main.js (line 48306, col 16)

here my configuration on gulpfile.js

var gulp        = require('gulp');
var durandal    = require('gulp-durandal');

gulp.task('default', function(cb)
{
    durandal({
            baseDir: 'public_html/app',
            main: 'main.js',
            output: 'main.js',
            almond: true,
            minify: false
        })
        .on('error', function(err) {
            console.error('error. ' + err);
        })
        .pipe(gulp.dest('public_html/build'))
        .on('end', cb);
});

I'm also came across with this answer https://stackoverflow.com/a/23329383/1889014

But i'm not sure if this is related to my issue.

Can someone please help or guide me through this ? Thanks!


Solution

  • I also had this issue using gulp, Durandal and modal dialogs. Adding a getView function to the viewmodel that returns the url for the view fixes it.

    eg

    function getView() {
        return "views/theView.html";
    }
    

    I am sure there must be a better way of solving this problem but this seems to work in the few places I have needed it.