ENOENT on nonexistant glob directory with gulp v5.0.1
Before you open this issue, please complete the following tasks:
- [x] use the search bar at the top of the page to search this repository for similar issues or discussions that have already been opened.
- [ ] if you are looking for help from the gulp team or community, open a discussion.
- [ ] if you think there is a problem with the plugin you're using, open a discussion.
- [x] if you think there is a bug in our code, open this issue.
What were you expecting to happen?
src glob on nonexistent directory to successfully no-op.
What actually happened?
An ENOENT error was thrown.
Please give us a sample of your gulpfile
const { src, dest } = require('gulp');
function defaultTask(cb) {
return src('input/*.js')
.pipe(dest('output/'));
}
exports.default = defaultTask
Terminal output / screenshots
Error: ENOENT: no such file or directory, scandir '/project/input'
Please provide the following information:
- OS & version [e.g. MacOS Catalina 10.15.4]: RHEL 8
- node version (run
node -v): 24.0.1 - npm version (run
npm -v): 11.3.0 - gulp version (run
gulp -v): 5.0.1
Additional information
On attempting to upgrade from gulp v5.0.0 to v5.0.1, an error is thrown that was not thrown before.
In v5.0.0, if the parent directory of the glob didn't exist, nothing was copied and the gulp build proceeded without error.
In v5.0.1, an ENOENT error is now thrown, breaking the build.
This is a duplicate of https://github.com/gulpjs/glob-stream/issues/134
It was present in gulp v5 but the globbing was finishing before the stream started so the error was lost.
I'm still on the fence about whether this is actually a bug. We don't allow empty "singular" globs, so why would we allow globs on directories that don't exist? Seems like a bug in the program. Even the original issue said that a failed build is probably the correct behavior.
Can you provide details on why you'd make a task like this?
Thanks, and apologies for not finding that issue first.
We have task definitions like this for re-use, standardized layouts, and future proofing. I think the alternative here for us is to comment out the tasks that refer to unused paths and remember to uncomment them if a file is added to the project under that path in the future.
Obviously not a big deal if that's how you feel this should be approached, I just expected the task to be a no-op, similar to how it would be if the directory existed but no files matched the glob.
Re-use makes sense. One solution I saw in a linked PR was to use fs.existsSync before trying to use a glob.
I'm also considering if we expand allowEmpty to work on glob directories so the error occurs by default but users can disable if they have a specific use case.
I'll need some more time to think about this.
I’ve upgraded from Gulp v4 to v5 and encountered this issue.
I have a Gulpfile that handles building JavaScript and CSS assets for a legacy website. It’s over 1000 lines long and manages more than 400 JavaScript and CSS files across various directories.
Our process involves first searching for all directories that match the pattern **/assets/src. Then, we append patterns like src/js/*.{ts,tsx}, src/js/*.{js,jsx}, src/css/*.css, and src/scss/*.scss to the matched directory paths. Directories assets/src/js or assets/src/css may not exist under every match. We search for the directories before the files, since the build options can be customized per directory using a config file.
Additionally, we have a watch task, which works even if the directory is created after the task is started.