1

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!

Community
  • 1
  • 1
Fariz Azmi
  • 713
  • 1
  • 6
  • 21

3 Answers3

3

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.

mallen
  • 106
  • 1
  • 4
  • Adding a getView function didn't work for me. Instead I explicitly called the view in the define: `define(['knockout', 'text!views/modalView.html'], function (ko) { ... });` – oragorn Apr 24 '15 at 19:33
1

I have experienced this error due to writing the view name using the wrong case. E.g. if the file is called myView.html but you require 'MyView'.

Anders
  • 11
  • 1
0

I am not building using gulp-durandal because it's giving very odd errors, and requirejs is working much better directly. I fixed this error by including all views manually in my requirejs build config.

include: [
    'text!customWidgets/alertsSection/title.html', //custom
    'text!customWidgets/alertsSection/body.html', //custom

    'text!customWidgets/exclusions/body.html', //custom
    'text!customWidgets/exclusions/title.html', //custom

    'text!customWidgets/submit/body.html', //custom
    'text!customWidgets/submit/title.html', //custom
]

There are many more files in my include due to the nature of durandal and the dynamic loading of views... but I don't want to spam everyone :)

SgtPooki
  • 11,012
  • 5
  • 37
  • 46