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.42k stars 2.12k forks source link

API- error undefined - Most infuriating bug ever #7878

Closed amlcodes closed 3 years ago

amlcodes commented 3 years ago

I dont know at this point anymore. I have done everything, lock files, node modules, cache, etc. pulled my amplify app. Any time I use my api, I get a credential error when trying to use IAM, and an undefined error when using cognito. no where to go, cloudwatch logs are all clean. NEXTJS

amlcodes commented 3 years ago

looks like nothing is being read by amplify.configure()

nubpro commented 3 years ago

Can u take a screenshot of the error you're getting?

amlcodes commented 3 years ago

@nubpro literally "undefined" is my error if i use cognito user pools as my authmode.

if I use graphqloperation() which should assume my default provider (cognito), it will try to use IAM, which tells me it looks like Amplify.configure(awsexport) or Amplify.configure({...awsexport, ssr: true}) on my nexjs page or _app.js is not being recognized. Happens during literally any client side api request using Cognito - however when using SSR.API using IAM and getServerSideProps() while loading the same page, the request succeeds.

Client side api requests using iam fails with "error no credentials" Client side api requests using cognito fail with "undefined" as error in a try/catch server side api requsts using iam succeeds as normal.


        await API.graphql(
          graphqlOperation(createContent, {
            input: {
              id: id
            },
          })
        )
      } catch (error) {
        console.log({ error })
      }
amlcodes commented 3 years ago

This makes absolutely zero sense to me. I have tried cloning my repo and pulling my app, and I get the same results. I used previously working package.json deps, and it does the same.

amlcodes commented 3 years ago

To reiterate: This is a horrendous bug and has completely halted the project. Running queries or mutations server side with getServerSideProps with NEXTJS and SSR.API importing from 'aws-ampilfy' works, as well as IAM or Cognito User Pools requests in the Appsync Queries Console.

When making any client side request with API importing from 'aws-amplify' - explicitly using 'AMAZON_COGNITO_USER_POOLS' as authMode, I will catch an error - however it will be undefined and useless. If I use "AWS_IAM" as authMode or not set authMode, I will get an error "Error: no credentials".

However I can remove my Amplify.configure line at _app.js as well as my /pages/page.js and see an error warning me amplify is not configured, just as well ssr requests stop working, as well as Auth. I have globally searched my project and I am only importing modules from 'aws-amplify' and not '@aws-amplify/api' or the like.

For some reason API is not recognizing any configuration client side. I have set up a new project directory and this still occurs, I have removed package-lock.json, reverted back to a list of working package versions, delete and reinstall node_modules, amplify folder and aws-exports.js and amplify pulled from the console command. less than successful, this was working before an npm update.

amlcodes commented 3 years ago

I had created a package of useful amplify hooks with amplify as a regular dependency, and left it in package.json ----- my b. It was only for Auth but that was definitely the issue.

Shomari commented 2 years ago

@amlcodes can you go into a bit more detail as to what happened with your package.json? I'm facing a similar issue

amlcodes commented 2 years ago

I had a custom module as a dependency with outdated amplify dependencies

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.