如何解决“ sequelize:找不到命令”?

时间:2019-09-23 17:22:50

标签: node.js terminal sequelize.js

这真令人沮丧。我正在尝试为node.js安装sequalize。我在本地成功安装了它,但是无法在全局上安装它(我收到以下权限被拒绝的错误:

 \'../lib/node_modules/sequelize-cli/lib/sequelize\').

我实际上并不真正希望将其全局安装,但是当在本地安装时,应该配置并初始化sequelize模块(通过键入 sequelize init:models和sequelize init:config < / strong>在终端中),出现以下错误:

-bash: sequelize: command not found

因此,我做了家庭作业,发现可以通过全局安装(-bash: sequelize: command not found)解决未找到命令错误,并且为了修复启用全局安装的错误,我更改了用户访问权限(Error: EACCES: permission denied, access '/usr/local/lib/node_modules' react ),但这并不能解决问题,我仍然无法获得许可。

所以我的问题是如何在终端中运行 sequelize init:models和sequelize init:config 而不找到命令?

4 个答案:

答案 0 :(得分:1)

您需要按以下步骤安装:

npm install --save sequelize
npm install --save sequelize-cli

如果没有,请安装npx 初始化续集:

npx sequelize init

答案 1 :(得分:0)

您需要安装

npm install --save sequelize
npm install --save sequelize-cli

然后根据to documentation运行CLI。无需全局安装。

$ npx sequelize --help

Sequelize CLI [Node: 10.0.0, CLI: 5.5.1, ORM: 5.19.0]

sequelize [command]

Commands:
  sequelize db:migrate                        Run pending migrations
  sequelize db:migrate:schema:timestamps:add  Update migration table to have timestamps
  sequelize db:migrate:status                 List the status of all migrations
  sequelize db:migrate:undo                   Reverts a migration
  sequelize db:migrate:undo:all               Revert all migrations ran
  sequelize db:seed                           Run specified seeder
  sequelize db:seed:undo                      Deletes data from the database
  sequelize db:seed:all                       Run every seeder
  sequelize db:seed:undo:all                  Deletes data from the database
  sequelize db:create                         Create database specified by configuration
  sequelize db:drop                           Drop database specified by configuration
  sequelize init                              Initializes project
  sequelize init:config                       Initializes configuration
  sequelize init:migrations                   Initializes migrations
  sequelize init:models                       Initializes models
  sequelize init:seeders                      Initializes seeders
  sequelize migration:generate                Generates a new migration file   [aliases: migration:create]
  sequelize model:generate                    Generates a model and its migration  [aliases: model:create]
  sequelize seed:generate                     Generates a new seed file             [aliases: seed:create]

Options:
  --help     Show help                                                                           [boolean]
  --version  Show version number                                                                 [boolean]

答案 2 :(得分:0)

我的问题的答案已解决,如vitamadio在评论中所述,在sudo的帮助下将其全局安装。所以answear就是这样安装的:

sudo npm install -g sequelize 

然后:

sudo npm i -g sequelize-cli

答案 3 :(得分:0)

按照下面的方法做应该没问题 npm install --save 续集 npm install --save sequelize-cli npx 续集初始化