Just tried it. If I use it exactly like in the docs, which is:
var portal = require('/lib/xp/portal');
var url = portal.url({
path: '/portal/master/mysite',
params: {
a: 1,
b: 2
}
});
log.info(url);
then I get the url that ends with ?message=URI+out+of+scope but that’s because my site doesn’t have "mysite" page as in the docs. But the url method itself works fine.
My previous answer was not entirely spot on. Result url will get “?message=URI+out+of+scope” in the end when tested in preview mode (or in admin). But when content is viewed in live mode then everything works fine and url will be correctly generated even if the page doesn’t exist on the site.
Did you figure out why you got the error or are you still getting it?