All jobs

Fix "TypeError: sequelize.import is not a function" after upgrading to Sequelize 6

Yes. An agent replaces sequelize.import with model factories, fixes the findById and string-operator calls that break next, and loads the models on Sequelize 6.

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 model loader and every query before changing a version, because sequelize.import is only the first thing Sequelize 6 removes. In a GraphQL server like the-road-to-graphql/fullstack-apollo-express-postgresql-boilerplate, package.json pins sequelize at ^4.41.2 (4.41.2 in the lock file), pg at ^7.6.1, bcrypt at ^3.0.2 and engines at Node 10.11.0. src/models/index.js builds a Sequelize from DATABASE_URL or three env variables and then calls sequelize.import('./user') and sequelize.import('./message'); user.js and message.js each export a (sequelize, DataTypes) => ... factory. Elsewhere, findById is called five times (resolvers/authorization.js, resolvers/message.js and three places in resolvers/user.js), loaders/user.js filters with the string operator $in, and resolvers/message.js already uses Sequelize.Op.lt. src/index.js calls sequelize.sync({force: isTest || isProduction}) before listening on port 8000.

Then it reproduces. On Node 22, npm install fails before Sequelize is even involved: bcrypt@3.0.2 has no prebuilt binary for the node-v127 ABI and the node-gyp build fails, so the agent installs bcrypt@5, which loads. With Sequelize 4.41.2 a probe that loads the models prints the deprecation sequelize deprecated String based operators are now deprecated and reports sequelize.import and User.findById as functions. After npm install sequelize@6 (6.37.8), loading src/models/index.js throws TypeError: sequelize.import is not a function at line 26.

The fix imports the two factories directly, import getUserModel from './user', and calls getUserModel(sequelize, Sequelize.DataTypes) and the same for messages; associate runs unchanged. With that, the models load on 6.37.8 and the probe shows sequelize.import as undefined, User.findById as undefined and User.findByPk as a function, which is the second change: the five findById calls become findByPk. The $in in loaders/user.js becomes [Sequelize.Op.in], the symbol form resolvers/message.js already uses, since Sequelize 4 flagged the string form as deprecated at startup.

Proof stops at the database boundary, and the agent says so. With pg 7.6.1 on Node 22, sequelize.authenticate() against no server never answers within 20 seconds; with pg@8 (8.23.1) it answers SequelizeConnectionRefusedError at once, so the pull request bumps pg too and shows both probes. The src/tests/user.spec.js suite needs a running server and a test database per the README, which the sandbox does not have, so the pull request carries the model-loading probes and leaves the end-to-end run to CI with Postgres.

Start it with one API call

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

{
  "agent": "claude",
  "input": "Our server throws \"TypeError: sequelize.import is not a function\" after moving to Sequelize 6. Read the model loader and every model, resolver and loader, list each Sequelize API we use that changed between our version and 6 (sequelize.import, findById, string operators such as $in), and say which versions the lock file installs for sequelize, pg and any native module. Replace sequelize.import with direct calls to the model factories, update the other removed calls, and load the models without a database to show the loader works; then check that the pg driver answers a connection attempt on the current Node and bump it if it hangs. Open a pull request with every call site changed and the probe output before and after.",
  "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 rewrites src/models/index.js to call the two model factories with Sequelize.DataTypes, renames five findById calls to findByPk, replaces $in with [Op.in] in the user loader, and bumps pg to 8 and bcrypt to 5 in package.json. The description lists every file and line, quotes the sequelize.import TypeError, and shows the loader probe output on 4.41.2 and on 6.37.8.

A reviewer checks that each factory is called with the same (sequelize, DataTypes) signature it declared, that associate still runs for both models, and that no findById or string operator remains. They also see the pg evidence: 7.6.1 hanging on Node 22 and 8.23.1 answering with a connection error.

The description states what the sandbox could not run: sync({force}) and src/tests/user.spec.js need Postgres, so those run in CI with a database, and the engines field still saying Node 10.11.0 is flagged for the maintainers.

Run it on every Dependabot pull request that bumps sequelize

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 loader and query changes onto the bump's branch when the model probe fails.

For several services built from the same boilerplate, 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 ORM upgrade fails in layers: the loader first, then the query methods it hid, then a driver that is too old for the Node that runs it. In a Rush sandbox the agent installs each version, loads the models without a database, and probes the driver with a timeout, so the pull request lists every call site from the repository's own code rather than from a changelog summary.

Native modules and old drivers make this a job nobody wants on a laptop with a different Node. The agent reports the bcrypt build failure, the pg hang and the test suite's database requirement as facts with versions, so the reviewer knows exactly what was proven and what CI still has to run.

Frequently asked questions

What replaces sequelize.import?

Calling the model file's exported factory yourself: import getUserModel from './user' and getUserModel(sequelize, Sequelize.DataTypes). The factories in this repository already take (sequelize, DataTypes), so their bodies do not change.

Why does findById break too?

Sequelize 6 has findByPk and no findById; the probe shows User.findById as undefined and User.findByPk as a function on 6.37.8. Five call sites in the resolvers change, nothing else.

Do I have to change $in and the other string operators?

Yes. Sequelize 4 already printed String based operators are now deprecated at start, and the pull request moves $in to [Sequelize.Op.in], the symbol form the message resolver already uses for Op.lt.

Why bump pg and bcrypt in the same pull request?

Because the upgrade cannot be verified without them on a current Node: bcrypt@3.0.2 fails to build on Node 22, and pg@7.6.1 never answers a connection attempt there while pg@8 answers at once. Both bumps are listed with their evidence; a team on Node 10 can split them out.

More Sequelize jobs

More jobs like this: Fix a bug from an alert

Keep reading