Gulp-useref is throwing error: “path must be a string”

前端 未结 1 1165
梦如初夏
梦如初夏 2021-01-27 00:35

I\'m using a gulpfile.js generated by yeoman\'s gulp-webapp generator and modified slightly by me to fit my needs. For some reason I keep running into an issue when

相关标签:
1条回答
  • 2021-01-27 01:03

    Short answer: TypeError: path must be a string means that there is an issue with the link/script paths. useref can't find the the file or directory you are pointing it to.

    Long answer:
    There were two issues I ran into.

    1. The link/script paths needs to be relative to the gulpfile or have an alternate directory to search.
    <!-- build:css /styles/main.css -->
    <link href="app/styles/base.css">
    <link href="app/styles/article.css">
    <!-- endbuild -->
    

    OR

    <!-- build:css(app) /styles/main.css -->
    <link href="/styles/base.css">
    <link href="/styles/article.css">
    <!-- endbuild -->
    
    1. The yeoman gulpfile uses multiple alt directories which requires you to put them inside curly braces like this:
    <!-- build:css({.temp,app}) /styles/main.css --> Works
    

    But if you only have one alt directory and you leave it in the curly braces it will throw an error.

    <!-- build:css({app}) /styles/main.css --> TypeError: path must be a string
    

    This is because it is reading the path as C:\path\to\project\{app}\styles\style.css. This seems like odd behavior to me. I would think that it would iterate through the directories listed in the braces regardless of the length.

    0 讨论(0)
提交回复
热议问题