How to fix amplify CLI error : "-bash: amplify: command not found"

How to fix amplify CLI error : "-bash: amplify: command not found"

我已经在我的笔记本电脑上安装了 amplify cli,尽管它抛出错误,但我还是使用了 amplify configure 命令并且它起作用了。但是现在当我试图在另一台笔记本电脑上做同样的事情时,它会抛出错误“-bash: amplify: command not found”。以下是整个错误块:

npm WARN deprecated @types/ora@3.2.0: This is a stub types definition. ora provides its own type definitions, so you do not need this installed.
npm WARN deprecated node-uuid@1.4.8: Use uuid module instead
/Users/.npm-global/bin/amplify -> /Users/.npm-global/lib/node_modules/@aws-amplify/cli/bin/amplify

> snappy@5.0.5 install /Users/.npm-global/lib/node_modules/@aws-amplify/cli/node_modules/snappy
> node-gyp rebuild

gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/Users/.npm-global/lib/node_modules/@aws-amplify/cli/node_modules/snappy/build'
gyp ERR! System Darwin 18.6.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/.npm-global/lib/node_modules/@aws-amplify/cli/node_modules/snappy
gyp ERR! node -v v10.16.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 

> zmq@2.15.3 install /Users/.npm-global/lib/node_modules/@aws-amplify/cli/node_modules/zmq
> node-gyp rebuild

gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/Users/.npm-global/lib/node_modules/@aws-amplify/cli/node_modules/zmq/build'
gyp ERR! System Darwin 18.6.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/.npm-global/lib/node_modules/@aws-amplify/cli/node_modules/zmq
gyp ERR! node -v v10.16.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 

> @aws-amplify/cli@3.11.0 postinstall /Users/.npm-global/lib/node_modules/@aws-amplify/cli
> node scripts/post-install.js

Ignore installation errors for optional dependencies: gyp, fs-ext


----------------------------------------
Successfully installed the Amplify CLI
----------------------------------------


Javascript Getting Started - https://aws-amplify.github.io/docs/js/start


Android Getting Started - https://aws-amplify.github.io/docs/android/start


iOS Getting Started - https://aws-amplify.github.io/docs/ios/start


npm WARN @conduitvc/mosca@2.8.3 requires a peer of leveldown@~1.4.3 but none is installed. You must install peer dependencies yourself.
npm WARN @conduitvc/mosca@2.8.3 requires a peer of ioredis@^1.15.1 but none is installed. You must install peer dependencies yourself.
npm WARN @conduitvc/mosca@2.8.3 requires a peer of mongodb@~2.1.4 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: snappy@5.0.5 (node_modules/@aws-amplify/cli/node_modules/snappy):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: snappy@5.0.5 install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: zmq@2.15.3 (node_modules/@aws-amplify/cli/node_modules/zmq):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: zmq@2.15.3 install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

+ @aws-amplify/cli@3.11.0

amplify 命令在另一台出现与上述相同错误的笔记本电脑上运行良好。我什至尝试按照 GitHub 上用户的建议使用 npm install -g @aws-amplify/cli --unsafe-perm=true 安装 cli。如果有人可以帮我解决这个问题,那就太好了。 TIA

在花了相当多的时间尝试分析错误之后,以下内容终于对我有用了:

  1. 已安装打字稿

  2. 已将 /usr/local/bin/node/usr/local/bin/npm 添加到路径

  3. 确保管理员负责使用以下命令访问文件:

    sudo chown -R ownername: /usr/local/lib/node_modules

  4. 终于使用这个命令安装了 amplify :

sudo npm install -g @aws-amplify/cli --unsafe-perm=true

通过执行这些步骤,即使出现错误,放大命令也能正常工作。

我找到的最好的方法是在 npm 安装的最后,你也可以看到它的安装路径。

/usr/local/Cellar/node/13.8.0/bin/amplify -> /usr/local/Cellar/node/13.8.0/lib/node_modules/@aws-amplify/cli/bin/amplify

您可以通过 运行 命令手动将此附加到您的路径:

export PATH=$PATH:/usr/local/Cellar/node/13.8.0/lib/node_modules/@aws-amplify/cli/bin/

就我而言,首先我必须从安装位置 运行 它。

/opt/homebrew/lib/node_modules/@aws-amplify/cli/bin/amplify

运行以上命令(amplify-cli安装路径(您可能有不同的位置))一次。

你好!现在尝试 amplify 作为命令,它将开始工作:]