Amplify-cli: "Select the backend providers" is empty when using npx

Created on 8 Feb 2019  Â·  22Comments  Â·  Source: aws-amplify/amplify-cli

Describe the bug
A clear and concise description of what the bug is.

Running amplify configure prompted to Select the backend providers, but screen is blank. Pressing ENTER terminates program.

To Reproduce
Steps to reproduce the behavior:

  1. Run npx amplify configure
  2. Observe blank screen under prompt
  3. Press ENTER (optional)
  4. Observe command finishes

Expected behavior
To see prompt options.

Screenshots

image

Desktop (please complete the following information):

  • OS: MacOS 10.14.3

    • npx: 9.7.1

    • amplify-cli: 0.1.45

bug installation

Most helpful comment

I have had the same symptoms when I installed the cli with sudo yarn global add @aws-amplify/cli.

Yarn chose to install the amplify command under /usr/local/bin as a symlink to /usr/local/share/.config/yarn/global/node_modules/.bin/amplify. However, the contents of the main amplify script were:

#!/usr/bin/env node
// run the CLI with the current process arguments
require('../src/cli').run(process.argv)

After removing the package with sudo yarn global remove @aws-amplify/cli and reinstalling with sudo npm install -g @aws-amplify/cli, it works correctly. The script linked to is still the same, but the link is stored at /usr/bin/amplify and points to /usr/lib64/node_modules/@aws-amplify/cli/bin/amplify.

The difference is that yarn is copying installed bin scripts into .bin, which does not have the adjacent src directory as expected because it is not running from the @aws-amplify/cli directory.

All 22 comments

@daviskoh thanks for reporting the issue. We don't support running Amplify CLI with npx yet. I will add this in our backlog to get this prioritized.

gotcha. i can take a look at it when i have some free time...

I noticed the same behavior when attempting to install amplify/cli into my project (with npm) as opposed to installing it globally.

@daviskoh We had some issues in older version of CLI when installed in project. What version of amplify cli were you trying to install in your project.

I'm seeing this with

dependencies: {
     ...
     "aws-amplify": "^1.1.19",
     ...
},
devDependencies: {
     ...
     "@aws-amplify/cli": "^0.2.1-multienv.42",
     ...
}

tried both:
npx amplify init and ./node_modules/.bin/amplify init

...

But:
It does work when using the npm i -g version, which is a decent workaround but not ideal for those of us who expect projects to be self containing
So in my case: npm i -g @aws-amplify/[email protected]
and using the globally available $> amplify
this issue goes away on all the subcommands that depend on OP's CLI question

~I'm seeing the same error, except for me I'm running $(npm bin)/amplify init in headless mode on a Jenkins worker where I don't have the option to install globally, so it's a blocker for me :/~

My case was fixed by deleting package-lock.json and re-installing. Probably had a bad old version of the amplify cli somewhere...

I have had the same symptoms when I installed the cli with sudo yarn global add @aws-amplify/cli.

Yarn chose to install the amplify command under /usr/local/bin as a symlink to /usr/local/share/.config/yarn/global/node_modules/.bin/amplify. However, the contents of the main amplify script were:

#!/usr/bin/env node
// run the CLI with the current process arguments
require('../src/cli').run(process.argv)

After removing the package with sudo yarn global remove @aws-amplify/cli and reinstalling with sudo npm install -g @aws-amplify/cli, it works correctly. The script linked to is still the same, but the link is stored at /usr/bin/amplify and points to /usr/lib64/node_modules/@aws-amplify/cli/bin/amplify.

The difference is that yarn is copying installed bin scripts into .bin, which does not have the adjacent src directory as expected because it is not running from the @aws-amplify/cli directory.

Can anyone offer insight on why amplify-cli thinks it needs to be installed globally?

@shader
in yarn global add, /usr/local/share/.config/yarn/global/node_modules/.bin/amplify is also a symlink, it points to the correct package, in which the ../src/cli can be correctly resolved.
I tested the latest version, the yarn global add is working, please remove your installation and try again, and let us know.

@disruptek
The amplify cli probably does not think it will only be installed globally, maybe its developers have not covered all the different installation scenarios.
We are working to improve this part of the user experience, PR #1004 covers some additional scenarios.

@UnleashedMind
You're right; - it does ultimately point to the bin directory of @aws-amplify/cli, so resolving ../src/cli shouldn't be the problem. In fact, that seems obvious in retrospect, since it's obviously doing _something_. The problem seems to be that it's not correctly locating the other node modules.

I think the problem may be related to the fact that I installed via sudo, and the system-level yarn packages are not discovered correctly.

When I originally tried yarn global add @aws-amplify/cli without sudo, I got errors preventing installation. It tries to install fsevents, which has event-stream "~3.3.0" as a dependency. That resolves to event-stream-3.3.6, which is listed as a version in the yarn registry, but for some reason is not actually available. The latest ~3.3.0 version actually available for download is 3.3.5. It fails to retrieve 3.3.6 with a 404 error, and gives up on installing in the $HOME/.config/yarn/global directory.

I installed with sudo, and instead of silently installing fsevents and failing on event-stream, it said linux was not compatible with fsevents and decided not to install it as an optional dependency. I don't know why it behaved differently, but the result is that it did not try to install event-stream and succeeded.

The empty providers problem is caused by the different install location. The yarn prefix code detection code fails, because it's not running from $HOME/.config/yarn/global, but in /usr/local/share/.config/yarn/global. Yarn doesn't install recursive node_modules in the @aws-amplify/cli directory, so the local node_modules detection returns nothing. Meanwhile, even though I have had it installed with sudo npm install -g at the same time, npm only installs the top package in the global /usr/lib/node_modules directory; all of the other dependencies get installed in a local recursive node_modules location, so those can't be found that way either. Consequently, no plugins are found when installed via sudo yarn global add.

If that's the case, then I guess this should be made separate issues for installing with yarn, both to fix the fsevents installation issue, and support sudo global add. It does give a hint that npx may be having the same issues with node_modules plugin detection too though.

@shader could you create an separate issue

@daviskoh the latest version of amplify cli works with npx. Please re-open the issue if you still can't use it with npx.

@yuth do you have documentation on the amplify cli working with npx? I have amplify-cli 3.11.0 installed as a devDependency in my project. When I run various npx amplify commands I get errors.

$ npx amplify status
Scanning for plugins...
Plugin scan successful

Current Environment: dev

| Category | Resource name | Operation | Provider plugin |
| -------- | ------------- | --------- | --------------- |

The 'request' argument must be string. Received type undefined
TypeError [ERR_INVALID_ARG_TYPE]: The 'request' argument must be string. Received type undefined`

Its recommended to install Amplify CLI globally in your machine and not as a dev Dependecy for your project.

I could not reproduce this issue when I rannpx amplify ls. Could you please install Amplify CLI globally and see if you are still getting this error.

Yes, everything works fine if I have Amplify installed globally. I am trying to use npx as an alternative to doing a global install of Amplify - where Amplify is a devDependency local to the project.

Above when you said "the latest version of amplify cli works with npx" I interpreted that as being able to use it locally without a global install.

Ran into this today. It does not work locally.

In this example, GitHub is my working directory, and I create amplify-local to test it out with npx/running amplify as a local dependency.

➜  GitHub clear
➜  GitHub mkdir amplify-local && cd amplify-local
➜  amplify-local npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (amplify-local)
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to /Users/bradgreenwald/GitHub/amplify-local/package.json:

{
  "name": "amplify-local",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}


Is this OK? (yes)
➜  amplify-local ls
package.json
➜  amplify-local npm i @aws-amplify/cli
npm WARN deprecated @types/[email protected]: This is a stub types definition. ora provides its own type definitions, so you do not need this installed.

> [email protected] install /Users/bradgreenwald/GitHub/amplify-local/node_modules/fsevents
> node install

node-pre-gyp WARN Using request for node-pre-gyp https download
[fsevents] Success: "/Users/bradgreenwald/GitHub/amplify-local/node_modules/fsevents/lib/binding/Release/node-v67-darwin-x64/fse.node" is installed via remote

> [email protected] postinstall /Users/bradgreenwald/GitHub/amplify-local/node_modules/core-js
> node scripts/postinstall || echo "ignore"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> @aws-amplify/[email protected] postinstall /Users/bradgreenwald/GitHub/amplify-local/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 notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] No description
npm WARN [email protected] No repository field.

+ @aws-amplify/[email protected]
added 1616 packages from 1413 contributors and audited 116534 packages in 27.972s
found 162 low severity vulnerabilities
  run `npm audit fix` to fix them, or `npm audit` for details
➜  amplify-local grep amplify package.json
  "name": "amplify-local",
    "@aws-amplify/cli": "^3.14.0"
➜  amplify-local npx amplify configure
Scanning for plugins...
Plugin scan successful
? Select the backend providers. (Press <space> to select, <a> to toggle all, <i> to invert selectio
n)
➜  amplify-local

the latest version of amplify cli works with npx. Please re-open the issue if you still can't use it with npx.

This issue should be re-opened.

Or, the docs could at least provide an explanation as the why a global install is required. Or, provide information that "We don't support running Amplify CLI with npx yet." is indeed accurate.

I have the exact same bug as @daviskoh.

And like @dave-moser, I am also trying to use npx as an alternative to doing a global install of Amplify (because global install is a deprecated method in general).

Here is my package.json:

dependencies: {
     ...
     "aws-amplify": "^2.2.7",
     ...
},
devDependencies: {
     ...
     "@aws-amplify/cli": "^4.17.2",
     ...
}

This issue should be re-opened, it's a pretty frustrating bug.

I'm still hitting this exact issue. Installed with yarn global add @aws-amplify/cli.

image

@devth Please use npm install -g @aws-amplify/cli

@kaustavghosh06 thanks, that works. Didn't realize I couldn't use yarn.

I confirmed today this problem still exists for local installs via yarn and run via npx.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

onlybakam picture onlybakam  Â·  3Comments

ReidWeb picture ReidWeb  Â·  3Comments

YikSanChan picture YikSanChan  Â·  3Comments

amlcodes picture amlcodes  Â·  3Comments

gabriel-wilkes picture gabriel-wilkes  Â·  3Comments