#1246·shelljs

Backslashes do not work on Windows after switch to fast-glob

Author: BrendanC23Created Mar 11, 2026Updated May 15, 2026
Labelsfixglob

The switch to fast-glob broke the handling of paths with backslashes on Windows.

This seems to be a limitation of the fast-glob library. From the README:

Always use forward-slashes in glob expressions (patterns and ignore option). Use backslashes for escaping characters. [...] Use the .convertPathToPattern package to convert Windows-style path to a Unix-style path.

This test passes with previous versions but now fails:

typescript
test('cp with Windows-style backslash and glob pattern', t => {
  const result = shell.cp('test\\resources\\file*.txt', t.context.tmp);
  t.falsy(shell.error());
  t.falsy(result.stderr);
  t.is(result.code, 0);
  t.truthy(fs.existsSync(`${t.context.tmp}/file1.txt`));
  t.truthy(fs.existsSync(`${t.context.tmp}/file2.txt`));
});

One workaround is to change this line to the following:

typescript
ret = glob.sync(glob.convertPathToPattern(convertQuestionMarkForGlob(listEl)), globOpts);

This fixes this specific test case, I'm not sure if this will cause problems in other tests or on other platforms. I tried running all of the existing tests locally but ran into issues with different numbers of tests running each time. Even before making the change, there were also many failing tests (on both Windows and WSL).

Also see https://github.com/shelljs/shx/issues/245, which describes the same issue with the shx package.