aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.43k stars 2.12k forks source link

Error: More than one or no providers are configured, Either specify a provider name or configure exactly one provider #9177

Closed adi518 closed 2 years ago

adi518 commented 2 years ago

Before opening, please confirm:

JavaScript Framework

React

Amplify APIs

Predictions

Amplify Categories

predictions

Environment information

``` # Put output below this line System: OS: macOS 11.6 CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Memory: 32.07 MB / 32.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 14.17.0 - /usr/local/bin/node Yarn: 1.22.15 - ~/.yarn/bin/yarn npm: 7.20.1 - /usr/local/bin/npm Browsers: Chrome: 95.0.4638.69 Safari: 15.0 npmPackages: @aws-amplify/predictions: ^4.0.22 => 4.0.22 (3.2.34) @aws-amplify/ui-react: ^0.2.38 => 0.2.38 @babel/eslint-parser: ^7.14.2 => 7.15.0 @craco/craco: ^6.1.1 => 6.2.0 @extra-array/binary-search.closest: ^1.1.7 => 1.1.7 @foobar404/wave: ^1.2.7 => 1.2.7 @graphql-codegen/cli: ^2.1.1 => 2.1.1 @graphql-codegen/visitor-plugin-common: ^2.1.0 => 2.1.2 @material-ui/core: ^4.11.3 => 4.12.3 @material-ui/icons: ^4.11.2 => 4.11.2 @material-ui/lab: ^4.0.0-alpha.57 => 4.0.0-alpha.60 @notdutzi/peaks.js: ^1.1.7 => 1.1.7 @notdutzi/react-easy-sort: ^1.3.9 => 1.3.9 @notdutzi/react-konva: ^17.0.3 => 17.0.3 @notdutzi/react-mosaic-component: ^5.0.2 => 5.0.2 @notdutzi/react-textarea-autosize: ^8.3.5 => 8.3.5 @reach/combobox: ^0.13.2 => 0.13.2 @reach/slider: ^0.13.2 => 0.13.2 @react-aria/listbox: ^3.3.0 => 3.3.1 @react-hook/resize-observer: ^1.2.0 => 1.2.2 @reduxjs/toolkit: ^1.6.0 => 1.6.1 @reduxjs/toolkit-query: 1.0.0 @reduxjs/toolkit-query-react: 1.0.0 @sentry/react: ^6.2.1 => 6.11.0 @sentry/tracing: ^6.2.1 => 6.11.0 @storybook/addon-actions: ^6.1.20 => 6.3.7 @storybook/addon-essentials: ^6.1.20 => 6.3.7 @storybook/addon-links: ^6.1.20 => 6.3.7 @storybook/addons: ^6.1.20 => 6.3.7 @storybook/node-logger: ^6.1.20 => 6.3.7 @storybook/preset-create-react-app: ^3.1.6 => 3.2.0 @storybook/react: ^6.1.20 => 6.3.7 @storybook/theming: ^6.1.20 => 6.3.7 @szhsin/react-menu: ^2.0.1 => 2.0.1 @testing-library/jest-dom: ^5.11.4 => 5.14.1 @testing-library/react: ^11.1.0 => 11.2.7 @testing-library/user-event: ^12.1.10 => 12.8.3 @types/classnames: ^2.2.11 => 2.3.1 @types/color: ^3.0.1 => 3.0.2 @types/cypress-image-snapshot: ^3.1.6 => 3.1.6 @types/download: ^6.2.4 => 6.2.4 @types/emoji-flags: ^1.2.0 => 1.3.0 @types/file-saver: ^2.0.2 => 2.0.3 @types/graphql: ^14.5.0 => 14.5.0 @types/inquirer: ^7.3.1 => 7.3.3 @types/jest: ^26.0.15 => 26.0.24 (27.0.1) @types/lodash: ^4.14.168 => 4.14.172 @types/memoizee: ^0.4.5 => 0.4.6 @types/node: ^12.0.0 => 12.20.28 (16.7.8, 14.17.12) @types/papaparse: ^5.2.5 => 5.2.6 @types/react: ^17.0.0 => 17.0.19 @types/react-color: ^3.0.4 => 3.0.5 @types/react-dom: ^17.0.0 => 17.0.9 @types/react-redux: ^7.1.16 => 7.1.18 @types/react-router-dom: ^5.1.7 => 5.1.8 @types/react-select: ^4.0.15 => 4.0.17 @types/react-table: ^7.0.29 => 7.7.2 @types/react-window: ^1.8.3 => 1.8.5 @types/redux-logger: ^3.0.8 => 3.0.9 @types/rimraf: ^3.0.0 => 3.0.2 @types/string-similarity: ^4.0.0 => 4.0.0 @types/twemoji: ^12.1.1 => 12.1.2 @types/uuid: ^8.3.0 => 8.3.1 @types/wavesurfer.js: ^3.3.1 => 3.3.2 @welldone-software/why-did-you-render: ^6.1.1 => 6.2.1 array-move: ^4.0.0 => 4.0.0 (3.0.1) assert: ^2.0.0 => 2.0.0 (1.5.0) aws-amplify: ^3.3.18 => 3.4.3 aws-amplify-react: ^5.0.4 => 5.0.11 aws-sdk: ^2.903.0 => 2.979.0 canvas: ^2.8.0 => 2.8.0 change-case: ^4.1.2 => 4.1.2 chromatic: ^5.6.3 => 5.9.2 circular-dependency-plugin: ^5.2.2 => 5.2.2 classnames: ^2.2.6 => 2.3.1 clipboard-copy: ^4.0.1 => 4.0.1 color: ^3.1.3 => 3.2.1 color-interpolate: ^1.0.5 => 1.0.5 colors: ^1.4.0 => 1.4.0 connected-react-router: ^6.9.1 => 6.9.1 console-clear: ^1.1.1 => 1.1.1 countries-list: ^2.6.1 => 2.6.1 craco-esbuild: ^0.3.0 => 0.3.4 cypress: 7.6.0 => 7.6.0 cypress-image-snapshot: ^4.0.1 => 4.0.1 debounced-drag: 1.0.0 dotenv: ^10.0.0 => 10.0.0 (8.6.0, 6.2.0, 8.2.0) download: ^8.0.0 => 8.0.0 emoji-flags: ^1.3.0 => 1.3.0 enquirer: ^2.3.6 => 2.3.6 eslint-plugin-cypress: ^2.11.3 => 2.11.3 face-api.js: ^0.22.2 => 0.22.2 file-saver: ^2.0.5 => 2.0.5 file-type: ^16.5.0 => 16.5.3 (4.4.0, 5.2.0, 6.2.0, 3.9.0, 11.1.0) get-blob-duration: ^1.2.0 => 1.2.0 graphql: ^15.5.1 => 15.5.2 (14.0.0) graphql-request: ^3.4.0 => 3.5.0 graphql-tag: ^2.12.4 => 2.12.5 hotkeys-js: ^3.8.7 => 3.8.7 inquirer: ^8.0.0 => 8.1.2 (7.3.3, 8.2.0) interweave: ^12.7.0 => 12.8.0 is-dark-color: ^1.2.0 => 1.2.0 iso-639-1-zh: ^2.0.4 => 2.0.4 jest-fetch-mock: ^3.0.3 => 3.0.3 jquery: ^3.6.0 => 3.6.0 kill-port: ^1.6.1 => 1.6.1 locale-codes: ^1.3.1 => 1.3.1 lodash: ^4.17.21 => 4.17.21 match-sorter: ^6.3.0 => 6.3.0 memoizee: ^0.4.15 => 0.4.15 moviedb-promise: ^3.1.8 => 3.1.9 msw: ^0.35.0 => 0.35.0 node-sass: ^5.0.0 => 5.0.0 node-sha1: ^1.0.1 => 1.0.1 node-webvtt: ^1.9.3 => 1.9.3 p-queue: 6.6.1 => 6.6.1 papaparse: ^5.3.0 => 5.3.1 parse-srt: ^1.0.0-alpha => 1.0.0-alpha pascal-case: ^3.1.2 => 3.1.2 patternomaly: ^1.3.2 => 1.3.2 pretty-bytes: ^5.6.0 => 5.6.0 pretty-ms: ^7.0.1 => 7.0.1 proxy-memoize: ^0.3.7 => 0.3.7 react: ^17.0.1 => 17.0.2 react-color: ^2.19.3 => 2.19.3 react-command-palette: ^0.16.2 => 0.16.2 react-dnd: ^14.0.2 => 14.0.3 (10.0.2) react-dnd-html5-backend: ^14.0.0 => 14.0.1 (10.0.2) react-dom: ^17.0.1 => 17.0.2 react-focus-lock: ^2.5.2 => 2.5.2 react-hot-toast: ^1.0.2 => 1.0.2 react-merge-refs: ^1.1.0 => 1.1.0 react-player: ^2.9.0 => 2.9.0 react-query: ^3.12.0 => 3.21.1 react-redux: ^7.2.2 => 7.2.4 react-router-dom: ^5.2.0 => 5.2.1 react-scripts: ^4.0.3 => 4.0.3 react-select: ^4.3.0 => 4.3.1 react-table: ^7.6.3 => 7.7.0 react-tiny-popover: ^6.0.5 => 6.0.10 react-use: ^17.1.1 => 17.2.4 react-window: ^1.8.6 => 1.8.6 reading-time: ^1.3.0 => 1.4.0 redux-logger: ^3.0.6 => 3.0.6 redux-todos-with-undo-example: 0.0.0 redux-undo: ^1.0.1 => 1.0.1 remove-accents: ^0.4.2 => 0.4.2 rimraf: ^3.0.2 => 3.0.2 (2.7.1) sourcemapped-stacktrace: ^1.1.11 => 1.1.11 string-similarity: ^4.0.4 => 4.0.4 svg-patterns: ^2.0.0 => 2.0.0 twemoji: ^13.0.1 => 13.1.0 type-fest: ^1.1.1 => 1.4.0 (0.20.2, 0.21.3, 0.8.1, 0.18.1, 0.6.0, 0.3.1) typescript: ^4.1.2 => 4.4.4 url-slug: ^3.0.1 => 3.0.2 use-deep-compare: ^1.1.0 => 1.1.0 use-intersection: ^0.2.1 => 0.2.1 uuid: ^8.3.2 => 8.3.2 (3.4.0, 3.3.2) virtual-dom-stringify: ^3.0.1 => 3.0.1 web-vitals: ^1.0.1 => 1.1.2 yargs: ^17.0.1 => 17.1.1 (16.2.0, 15.4.1, 13.3.2) zustand: ^3.3.3 => 3.5.10 npmGlobalPackages: npm: 7.20.1 yarn: 1.22.10 ```

Describe the bug

When I first added this category, it worked just fine. I then moved between branches and from amplify mock api to a real environment and now all I get is the error below. The only way I could make it work again is by going through the hassle of re-cloning and re-initiating Amplify. While debugging this, I found there's a very confusing way to consume the Predictions class. It can either be imported from aws-amplify or from @aws-amplify/predictions, my IDE autocomplete often picks the wrong import (the one that doesn't appear in the docs) and I suspect the SDK itself gets confused, because if I try to use Predictions from aws-amplify, it stops failing on a missing provider and throws an auth error.

Expected behavior

Translate successfully.

Reproduction steps

Add Predictions Move between branches Try to use a Predictions API

Code Snippet

export async function translate(textToTranslate: string, sourceLanguage: string, targetLanguage: string) {
  // see supported languages https://docs.aws.amazon.com/translate/latest/dg/how-it-works.html#how-it-works-language-codes
  return await Predictions.convert({
    translateText: {
      source: { text: textToTranslate, language: sourceLanguage },
      targetLanguage: targetLanguage,
    },
  });
}

Log output

```js // Put your logs below this line index.js:1 Error: More than one or no providers are configured, Either specify a provider name or configure exactly one provider at PredictionsClass.push../node_modules/@aws-amplify/predictions/lib-esm/Predictions.js.PredictionsClass.getPluggableToExecute (Predictions.js:137) at PredictionsClass.push../node_modules/@aws-amplify/predictions/lib-esm/Predictions.js.PredictionsClass.convert (Predictions.js:116) at utils.ts:415 at Generator.next () at translation-utils.ts:17 at new Promise () at __async (translation-utils.ts:17) at translate (utils.ts:413) at Cue.tsx:168 at Generator.next () at Cue.module.scss?2b38:82 at new Promise () at __async (Cue.module.scss?2b38:82) at Cue.tsx:163 at invokeFunc (debounce.js:95) at trailingEdge (debounce.js:144) at timerExpired (debounce.js:132) ```

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

stocaaro commented 2 years ago

@adi518 Thank you for the detailed capture of your environment. I have been troubleshooting a related issue and I suspect the solution will be the same for you.

The aws-amplify-react appears to cause other amplify packages to lock onto older versions causing this error. I would recommend removing aws-amplify-react and then reinstalling aws-amplify.

npm uninstall aws-amplify-react aws-amplify
npm install aws-amplify

If your project depends on some of amplify's react features, prefer upgrading to @aws-amplify/ui-react over using aws-amplify-react.

stocaaro commented 2 years ago

Closing this as we have not heard back from you. If you are still experiencing this issue and in need of assistance, please feel free to comment and provide us with additional information to debug further.

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.