Michael
Michael

Reputation: 13616

Gulp error - 'No path specified! Can not get relative.'

I using Gulp in my project in Visual Studio 2013.

I moved all my projects to new dev-machine. In project I use Gulp. Here is my task in gulpfile.js:

    config = {
        scripts: {
            src: "./app",
            destination: "./scripts/app"
        },
        templates: {
            src: "./app/**/*.tmpl.html",
            destination: "./scripts/app",
            filename: "templates"
        },
        build: {
            src: "./scripts/app/*.js",
            destination: "./scripts/build",
            filename: "dashboard-build"
        }
    }

  gulp.task("templates", function () {
    gulp.src(config.templates.src)
        .pipe(html2js({
            outputModuleName: "templates",
            useStrict: true
        }))
        .pipe(concat(config.templates.filename + ".js"))
        .pipe(gulp.dest(config.templates.destination))
});

When I try to fire the task command prompt window I get this error:

C:\Development\Repositories\Tambaound\Tambaound.Web>gulp templates
[17:04:59] Using gulpfile C:\Development\Repositories\Tambaound\Tambaound.Web\gulpfile.js
[17:04:59] Starting 'templates'...
[17:04:59] Finished 'templates' after 12 ms
C:\Development\Repositories\Tambaound\Tambaound.Web\node_modules\gulp-html2js\node_modules\gulp-util\node_modules\vinyl\index.js:120
    if (!this.path) throw new Error('No path specified! Can not get relative.');
                    ^

Error: No path specified! Can not get relative.
    at File.get (C:\Development\Repositories\Tambaound\Tambaound.Web\node_modules\gulp-html2js\node_modules\gulp-util\node_modules\vinyl\index.js:120:27)
    at Stream.bufferContents (C:\Development\Repositories\Tambaound\Tambaound.Web\node_modules\gulp-concat\index.js:35:20)
    at Stream.stream.write (C:\Development\Repositories\Tambaound\Tambaound.Web\node_modules\gulp-concat\node_modules\through\index.js:26:11)
    at DestroyableTransform.ondata (C:\Development\Repositories\Tambaound\Tambaound.Web\node_modules\gulp-html2js\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:531:20)
    at emitOne (events.js:96:13)
    at DestroyableTransform.emit (events.js:188:7)
    at readableAddChunk (C:\Development\Repositories\Tambaound\Tambaound.Web\node_modules\gulp-html2js\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:198:18)
    at DestroyableTransform.Readable.push (C:\Development\Repositories\Tambaound\Tambaound.Web\node_modules\gulp-html2js\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:157:10)
    at DestroyableTransform.Transform.push (C:\Development\Repositories\Tambaound\Tambaound.Web\node_modules\gulp-html2js\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:123:32)
    at DestroyableTransform._flush (C:\Development\Repositories\Tambaound\Tambaound.Web\node_modules\gulp-html2js\index.js:75:14)

While on my old machine all worked perfectly and all other tasks on new dev machine works fine. How can I solve this issue?

Upvotes: 1

Views: 496

Answers (1)

Sven Schoenung
Sven Schoenung

Reputation: 30564

You are probably using different versions of gulp-html2js on those two machines.

The following is an example taken straight from the README.md for v0.3.1 of gulp-html2js:

gulp.src('templates/*.html')
  .pipe(html2js({
     outputModuleName: 'template-test',
     useStrict: true,
     target: 'js'
  }))

That looks very much like the code you're trying to use.

However here's the same example taken from the README.md for v0.4.2 (latest version):

gulp.src('templates/*.html')
  .pipe(html2js('angular.js', {
     adapter: 'angular',
     base: 'templates',
     name: 'angular-demo'
  }))

Notice the difference? The ouputModuleName option seems to have been renamed to name. Also the first parameter for html2js() is now the filename for the new module. Your code is missing that and that's what's giving you the No path specified! error.

Normally something like this shouldn't happen. Modules should follow Semantic Versioning and breaking changes like this should only be introduced in major version changes. However v0.x.x is exempt from this rule:

Major version zero (0.y.z) is for initial development. Anything may change at any time. The public API should not be considered stable.

You have two options:

  1. Make sure you install the same version of gulp-html2js that you have on the old machine. Using v0.3.1 should do it:

    npm install --save-dev [email protected]  
    
  2. Adjust your task to look like the one in the example for version 0.4.2 above. The README for that version should help you with that.

(You might also want to look into using gulp-ng-html2js instead, which is a competing plugin that seems to be doing the same task, but has about three times as many downloads.)

Upvotes: 3

Related Questions