How to fix Unable to resolve sequelize package error

When running any sequelize-cli command from the Terminal, you may encounter an error saying Unable to resolve sequelize package.

Here’s an example of the error:

$ npx sequelize-cli init

Unable to resolve sequelize package in ...

This error happens because sequelize-cli requires the sequelize package to run.

To resolve this error, you need to install sequelize package locally in your project with the following command:

npm install sequelize

Once the sequelize package is installed, you may run the sequelize-cli command again.

The sequelize package is not bundled together with the CLI tool because you might use a different version of sequelize in your actual JavaScript project.

Bundling sequelize with sequelize-cli will cause you unable to choose which version of sequelize to use in your project.

One thing to keep in mind is that when you run sequelize-cli commands using npx, the sequelize package must be installed locally in your JavaScript project.

Installing sequelize globally on your computer will still trigger the same error:

$ npm install -g sequelize
$ npx sequelize-cli --version

Unable to resolve sequelize package in ...

When you install sequelize globally with -g flag, you also need to install sequelize-cli globally:

npm install -g sequelize-cli

Only then you can run the sequelize-cli commands.

When you install sequelize package both globally and locally, sequelize-cli will use the global package instead of the local one.

You can test this by calling sequelize-cli --version from the command line:

$ npm install [email protected]
$ sequelize-cli --version

Sequelize CLI [Node: 16.13.0, CLI: 6.3.0, ORM: 6.12.5]

6.3.0

In the output above, the ORM version is the sequelize package version used by sequelize-cli.

Even though I’ve installed [email protected] locally, the sequelize-cli package still uses the globally installed [email protected].

Using a different version of sequelize for the CLI may cause the CLI to generate code that is deprecated and cannot be run by the sequelize used in your JavaScript project.

This is why you are recommended to install sequelize package locally in your project and not globally. It ensures your CLI tool and web project use the same version of the package.

Great work on resolving sequelize package error! 👍

Take your skills to the next level ⚡️

I'm sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.