Search code examples
javascriptnode.jsgulp

How to resolve gulp issue with the file not found, even though file exists in my case


I'm figuring out how Gulp works, and following is a sample task,

function negativeGlobTest(){
    return src(["./src/**/*.js", "!./src/pop/*.js", "./src/pop/twopac.js"])
    .pipe(ugli())
    .pipe(rename({extname : ".min.js"}))
    .pipe(dest("./superOutput"))
}

and here is my output for the `ls -lR src

src:
total 1
-rw-r--r-- 1 terminator 197121 395 Apr  5 14:31 index.js 
drwxr-xr-x 1 terminator 197121   0 Apr  5 18:43 pop/     

src/pop:
total 2
-rw-r--r-- 1 terminator 197121 133 Apr  5 18:30 mao.js   
drwxr-xr-x 1 terminator 197121   0 Apr  5 14:30 pom/     
-rw-r--r-- 1 terminator 197121 154 Apr  5 18:34 twopac.js

src/pop/pom:
total 1
-rw-r--r-- 1 terminator 197121 29 Apr  5 18:27 index.js 

upon running the task I'm encountering the error

Error: File not found with singular glob: C:/my-github-repo/master/src/pop/twopac.js (if this was purposeful, use `allowEmpty` option)

clearly file exists, What am I doing wrong here ?

I think glob should first match all the files inside the src excluding all the files ending at js inside pop, and later allowing the twopac.js which is inside the pop.


Solution

  • The file has been removed from the stream how can you get it back in the same stream, you will have to explicitly add it back using the src() like this

    function negativeGlobTest(){
        return src(["./src/**/*.js", "!./src/pop/*.js"])
        .pipe(src("./src/pop/twopac.js"))
        .pipe(ugli())
        .pipe(rename({extname : ".min.js"}))
        .pipe(dest("./superOutput"))
    }