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
sequelize package is installed, you may run the
sequelize-cli command again.
sequelize package is not bundled together with the CLI tool because you might use a different version of
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
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
npm install -g sequelize-cli
Only then you can run the
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 firstname.lastname@example.org $ 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
Even though I’ve installed
email@example.com locally, the
sequelize-cli package still uses the globally installed
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
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! 👍