All jobs

Fix "TypeError: glob is not a function" after upgrading the glob package

Yes. An agent finds every callback-style glob call, moves each to the promise API that glob 9 and later export, and runs the test suite before and after.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads the call sites before touching the dependency, because glob 9 changed its export shape and every caller breaks in its own way. In a tool like kss-node/kss-node (version 3.1.0, engines Node 8 or newer), package.json declares "glob": "^7.1.6" and the lock file pins 7.1.6. There are two call sites: lib/traverse.js line 19 does const glob = require('glob') and wraps the callback form in a Bluebird promise at lines 21 to 25, called once with {nodir: true}; builder/base/kss_builder_base.js line 21 does glob = Promise.promisify(require('glob')) and calls it twice at lines 883 and 884 to find template files.

Then it reproduces. npm install and npm test (nyc mocha, then eslint as the posttest step) give the baseline: 457 passing and a clean lint. npm install glob@latest moves to 14.0.4, whose engines field reads 18 || 20 || >=22, and the suite no longer loads. The first failure is not the one in the search box: Bluebird throws TypeError: expecting a function but got [object Object] from Promise.promisify at kss_builder_base.js:21, because require('glob') is now an object of named exports. Only after that line is changed does lib/traverse.js:23 throw TypeError: glob is not a function, since glob(pattern, options, callback) is calling the module object.

The fix is the same in both files: const {glob} = require('glob'), and in traverse.js the hand-written promise wrapper becomes Promise.resolve(glob(pattern, options)), because the named glob export returns a promise and takes no callback. The agent adds .then(files => files.sort()) since glob 9 and later no longer sort results the way 7 did; the suite passes without it here, but a style guide's section order should not depend on directory iteration. One lint detail: the repository's eslint config has no-mixed-requires, so the destructured require goes on its own line rather than inside the const fs = ..., kssBuilderAPI = '3.0' declaration.

Proof is the suite on the new major: 457 passing again and npm run lint clean, with nodir: true still honoured by glob 14. The agent reports what it did not change: Bluebird stays for the fs-extra promisification, and the engines field still says Node 8 although the new glob needs 18, which is a decision for the maintainers.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Our Node tool throws \"TypeError: glob is not a function\" since the glob package was updated. List every file that requires glob and how each one calls it (callback, sync, or promisified), say which glob version the lock file installs and which version we moved to, and port every call to the named exports glob 9 and later provide, keeping results sorted where the old version sorted them. Run the full test suite and the linter before and after, and open a pull request with both results and the engine requirements of the new glob.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

A pull request that touches two source files: lib/traverse.js swaps the callback wrapper for the promise-returning named export with an explicit sort, and builder/base/kss_builder_base.js drops Promise.promisify around the module. The description lists both call sites with their lines, the two error messages in the order they appear, and the versions involved: 7.1.6 locked, 14.0.4 installed, Node 18 || 20 || >=22 required.

A reviewer checks that every glob call now goes through the named export, that the nodir option survives, and that the test count matches the baseline. They also see the lock file and package.json changes for glob and decide whether the engines field should move with them.

The description names the Bluebird error as the first thing a user hits, so anyone searching for that message instead of the glob one finds the same fix.

Run it on every Dependabot pull request that bumps glob

The error arrives with the bump, so the trigger is the pull request that bumps it. An automation with a github trigger on pull_request.opened and pull_request.synchronize runs this prompt on each one, with the event appended after the prompt, and pushes the call-site rewrite onto the bump's branch when the suite fails on a glob TypeError.

For many packages that still pin glob 7, your server sends this request once per repository, each with its own UUID as request_id so a retry returns the run already started, and reads each run.completed webhook; a key starts at most max_concurrent runs at once and queues the rest.

The use case this job follows, with its automation and trigger: Fix a bug from an alert.

Why run it on Rush?

A major version that changes the module's export shape fails in a different place for every caller, and the first error on screen is often a wrapper's message rather than glob's. In a Rush sandbox the agent installs both versions, runs the suite under each, and keeps every stack trace, so the pull request names each call site and the error it produced instead of a generic migration note.

The change is small but touches code that decides which files a build sees. The agent proves the suite and the linter pass on the new major and reports the engine requirement that comes with it, so the reviewer reads a few lines of diff with the evidence behind them.

Frequently asked questions

Why do I see a Bluebird or promisify error instead of glob's?

Because the module is now an object of named exports, anything that promisifies require('glob') fails first with a message about expecting a function. Once that wrapper is removed, the plain glob(pattern, options, callback) call fails with glob is not a function. Both come from the same change in glob 9.

Does glob 9 and later still take the nodir option?

Yes. The port keeps {nodir: true} and the suite's directory-walking tests pass unchanged on 14.0.4. What changed is the calling convention: the named glob export returns a promise and there is no callback argument.

Why add a sort if the tests pass without it?

glob 7 sorted its results by default; the newer majors return them in traversal order. The style guide's sections come from the file list, so the agent sorts explicitly to keep output stable across file systems, and says so in the pull request.

Will this work on the Node version in the engines field?

Not necessarily. kss-node's engines says Node 8 or newer, but glob 14.0.4 declares 18 || 20 || >=22. The pull request quotes both so the maintainers can raise the field or pin an older glob major on purpose.

More jobs like this: Fix a bug from an alert

Keep reading