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.13k forks source link

Cannot remove withAuthenticator in _app.tsx #11141

Closed Frankjunyulin closed 1 year ago

Frankjunyulin commented 1 year ago

Before opening, please confirm:

JavaScript Framework

React, Next.js

Amplify APIs

Authentication

Amplify Categories

No response

Environment information

``` System: OS: macOS 12.6 CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Memory: 2.32 GB / 32.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node Yarn: 1.22.19 - ~/.nvm/versions/node/v16.13.0/bin/yarn npm: 9.5.0 - ~/.nvm/versions/node/v16.13.0/bin/npm Watchman: 2021.10.18.00 - /usr/local/bin/watchman Browsers: Chrome: 111.0.5563.110 Safari: 16.0 npmPackages: @ampproject/toolbox-optimizer: undefined () @aws-amplify/core: ^5.0.15 => 5.0.15 @aws-amplify/ui-react: ^4.3.8 => 4.3.8 @aws-amplify/ui-react-internal: undefined () @babel/core: undefined () @babel/runtime: 7.15.4 @edge-runtime/primitives: 1.1.0-beta.31 @emotion/react: ^11.10.5 => 11.10.6 @emotion/styled: ^11.10.5 => 11.10.6 @hapi/accept: undefined () @headlessui/react: ^1.7.3 => 1.7.11 @heroicons/react: ^2.0.12 => 2.0.16 @mui/material: ^5.10.16 => 5.11.10 @napi-rs/triples: undefined () @next/react-dev-overlay: undefined () @prisma/client: ^4.10.1 => 4.10.1 @segment/ajv-human-errors: undefined () @types/node: 18.8.2 => 18.8.2 @types/react: ^18.0.21 => 18.0.28 @types/react-dom: ^18.0.6 => 18.0.11 @vercel/nft: undefined () acorn: undefined () amphtml-validator: undefined () arg: undefined () assert: undefined () async-retry: undefined () async-sema: undefined () autoprefixer: ^10.4.12 => 10.4.13 aws-amplify: ^5.0.15 => 5.0.15 babel-packages: undefined () browserify-zlib: undefined () browserslist: undefined () buffer: undefined () bytes: undefined () chalk: undefined () ci-info: undefined () cli-select: undefined () comment-json: undefined () compression: undefined () conf: undefined () constants-browserify: undefined () content-disposition: undefined () content-type: undefined () cookie: undefined () cross-spawn: undefined () crypto-browserify: undefined () cssnano-simple: undefined () debug: undefined () devalue: undefined () domain-browser: undefined () edge-runtime: undefined () eslint: 8.24.0 => 8.24.0 eslint-config-next: 12.3.1 => 12.3.1 events: undefined () find-cache-dir: undefined () find-up: undefined () fresh: undefined () get-orientation: undefined () glob: undefined () gzip-size: undefined () http-proxy: undefined () https-browserify: undefined () icss-utils: undefined () ignore-loader: undefined () image-size: undefined () is-animated: undefined () is-docker: undefined () is-wsl: undefined () jest-worker: undefined () json5: undefined () jsonwebtoken: undefined () loader-utils: undefined () lodash.curry: undefined () lru-cache: undefined () micromatch: undefined () mini-css-extract-plugin: undefined () nanoid: undefined () native-url: undefined () neo-async: undefined () next: ^12.3.1 => 12.3.4 node-fetch: undefined () node-html-parser: undefined () openai: ^3.1.0 => 3.2.1 ora: undefined () os-browserify: undefined () p-limit: undefined () path-browserify: undefined () postcss: ^8.4.17 => 8.4.21 (8.4.14) postcss-flexbugs-fixes: undefined () postcss-modules-extract-imports: undefined () postcss-modules-local-by-default: undefined () postcss-modules-scope: undefined () postcss-modules-values: undefined () postcss-preset-env: undefined () postcss-safe-parser: undefined () postcss-scss: undefined () postcss-value-parser: undefined () prisma: ^4.10.1 => 4.10.1 process: undefined () punycode: undefined () querystring-es3: undefined () raw-body: undefined () react: ^18.2.0 => 18.2.0 react-code-blocks: ^0.0.9-0 => 0.0.9-0 react-dom: ^18.2.0 => 18.2.0 react-is: 17.0.2 react-refresh: 0.12.0 react-server-dom-webpack: undefined () react-spinners: ^0.13.8 => 0.13.8 reactflow: ^11.0.0 => 11.5.6 regenerator-runtime: 0.13.4 sass-loader: undefined () schema-utils: undefined () semver: undefined () send: undefined () setimmediate: undefined () source-map: undefined () stream-browserify: undefined () stream-http: undefined () string-hash: undefined () string_decoder: undefined () strip-ansi: undefined () tailwindcss: ^3.1.8 => 3.2.7 tar: undefined () terser: undefined () text-table: undefined () timers-browserify: undefined () tty-browserify: undefined () typescript: 4.8.4 => 4.8.4 ua-parser-js: undefined () unistore: undefined () util: undefined () vm-browserify: undefined () watchpack: undefined () web-vitals: undefined () webpack: undefined () webpack-sources: undefined () ws: undefined () npmGlobalPackages: @aws-amplify/cli: 10.7.3 corepack: 0.10.0 node-prune: 1.0.2 npm: 9.5.0 pnpm: 7.13.4 prisma: 4.11.0 serverless: 3.28.0 yarn: 1.22.19 ```

Describe the bug

Cannot remove withAuthenticator in my _app.tsx file. Otherwise it would give the error while I run npm run build:

Error: You provided an `onClose` prop to the `Dialog`, but the value is not a function. Received: undefined
    at file:///Users/flin/workplay/Dear/dear/node_modules/@headlessui/react/dist/components/dialog/dialog.js:1:2873
    at Wc (/Users/flin/workplay/Dear/dear/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
    at Zc (/Users/flin/workplay/Dear/dear/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:73:362)
    at Z (/Users/flin/workplay/Dear/dear/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at Zc (/Users/flin/workplay/Dear/dear/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:74:209)
    at Z (/Users/flin/workplay/Dear/dear/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at Zc (/Users/flin/workplay/Dear/dear/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)
    at Z (/Users/flin/workplay/Dear/dear/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at Zc (/Users/flin/workplay/Dear/dear/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:74:209)
    at Z (/Users/flin/workplay/Dear/dear/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)

Error occurred prerendering page "/components/BotConfirm". Read more: https://nextjs.org/docs/messages/prerender-error
Error: You provided an `onClose` prop to the `Dialog`, but the value is not a function. Received: undefined
    at file:///Users/flin/workplay/Dear/dear/node_modules/@headlessui/react/dist/components/dialog/dialog.js:1:2873
    at Wc (/Users/flin/workplay/Dear/dear/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
    at Zc (/Users/flin/workplay/Dear/dear/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:73:362)
    at Z (/Users/flin/workplay/Dear/dear/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at Zc (/Users/flin/workplay/Dear/dear/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:74:209)
    at Z (/Users/flin/workplay/Dear/dear/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at Zc (/Users/flin/workplay/Dear/dear/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)
    at Z (/Users/flin/workplay/Dear/dear/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at Zc (/Users/flin/workplay/Dear/dear/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:74:209)
    at Z (/Users/flin/workplay/Dear/dear/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
undefined
Empty Bot
info  - Generating static pages (19/19)

If I don't change _app.tsx, build success.
> Build error occurred
Error: Export encountered errors on following paths:
    /components/BotConfirm
    at /Users/flin/workplay/Dear/dear/node_modules/next/dist/export/index.js:404:19
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Span.traceAsyncFn (/Users/flin/workplay/Dear/dear/node_modules/next/dist/trace/trace.js:79:20)
    at async /Users/flin/workplay/Dear/dear/node_modules/next/dist/build/index.js:1230:21
    at async Span.traceAsyncFn (/Users/flin/workplay/Dear/dear/node_modules/next/dist/trace/trace.js:79:20)
    at async /Users/flin/workplay/Dear/dear/node_modules/next/dist/build/index.js:1092:17
    at async Span.traceAsyncFn (/Users/flin/workplay/Dear/dear/node_modules/next/dist/trace/trace.js:79:20)
    at async Object.build [as default] (/Users/flin/workplay/Dear/dear/node_modules/next/dist/build/index.js:65:29)

Expected behavior

npm run build succeed

Reproduction steps

  1. Changed export default withAuthenticator(MyApp); to export default MyApp; in _app.tsx
  2. npm run build
  3. Build fail. Got above error

Code Snippet

// Put your code below this line.

Log output

``` // Put your logs below this line ```

aws-exports.js

/* eslint-disable */
// WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.

const awsmobile = {
    "aws_project_region": "us-east-1",
    "aws_cognito_identity_pool_id": "us-east-1:e1b23467-b561-4511-8c7a-91cda3bbc0cc",
    "aws_cognito_region": "us-east-1",
    "aws_user_pools_id": "us-east-1_hHUKoCPHp",
    "aws_user_pools_web_client_id": "57fh330o1c8lalef69g6i6h6dc",
    "oauth": {
        "domain": "dear3683324a-3683324a-dev.auth.us-east-1.amazoncognito.com",
        "scope": [
            "phone",
            "email",
            "openid",
            "profile",
            "aws.cognito.signin.user.admin"
        ],
        "redirectSignIn": "https://www.dearai.online/",
        "redirectSignOut": "https://www.dearai.online/",
        "responseType": "code"
    },
    "federationTarget": "COGNITO_USER_POOLS",
    "aws_cognito_username_attributes": [],
    "aws_cognito_social_providers": [],
    "aws_cognito_signup_attributes": [
        "EMAIL"
    ],
    "aws_cognito_mfa_configuration": "OPTIONAL",
    "aws_cognito_mfa_types": [
        "SMS"
    ],
    "aws_cognito_password_protection_settings": {
        "passwordPolicyMinLength": 8,
        "passwordPolicyCharacters": []
    },
    "aws_cognito_verification_mechanisms": [
        "EMAIL"
    ]
};

export default awsmobile;

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

tannerabread commented 1 year ago

Hi @Frankjunyulin can you provide some of your _app.tsx code? From the error, it looks like maybe you were using a prop passed from the authenticator somewhere in the code. withAuthenticator can send in props such as:

function App({ isPassedToWithAuthenticator, signOut, user })
Frankjunyulin commented 1 year ago

@tannerabread here is my previous code in _app.tsx:

import React, {useEffect, useState} from "react";
import type {NextPage} from "next";
import Head from "next/head";
import ChatComponent from "./components/ChatComponent";
import Bot from "./Bot";
import Document from "./Document";
import Router from "next/router";
import {Auth} from "aws-amplify";
import MoonLoader from "react-spinners/MoonLoader";
import TransitionBar from "./components/TransitionBar";
import Playground from "./Playground";
import dynamic from "next/dynamic";
import {withAuthenticator} from "@aws-amplify/ui-react";

/*
const DearWidget = dynamic(() => import("./components/DearWidget"), {
  ssr: false,
});
*/

type MainComponentProps = {
  status: String;
  setTransitionStatus: (val: String) => void;
};

function MainComponent({status, setTransitionStatus}: MainComponentProps) {
  if (status === "Bot") {
    return <Bot setTransitionStatus={setTransitionStatus} />;
  } else if (status === "Playground") {
    return <Playground setTransitionStatus={setTransitionStatus} />;
  } else {
    return <Document setTransitionStatus={setTransitionStatus} />;
  }
}

const Home: NextPage = () => {
  const [isSpinned, setIsSpinned] = useState(true);
  const [transitionStatus, setTransitionStatus] = useState<String>("Bot");
  const [userName, setUserName] = useState<String>("");
  const [userEmail, setUserEmail] = useState<String>("");

  useEffect(() => {
    const crrentUser = getUserInfo();

    console.log(crrentUser);
  }, []);

  const getUserInfo = async () => {
    const crrentUser = await Auth.currentUserInfo()
      .then((userInfo) => {
        console.log("user");
        console.log(userInfo);
        setUserName(userInfo.username);
        setUserEmail(userInfo.attributes.email);
        /*
        Router.push({
          pathname: "/Bot",
          query: {
            username: userInfo.username,
            email: userInfo.attributes.email,
          },
        });
        */
      })
      .finally(() => {
        setIsSpinned(false);
      });
    return crrentUser;
  };

  console.log();
  if (isSpinned === true) {
    return (
      <div className="flex h-screen items-center justify-center">
        <MoonLoader color="#36d7b7" />
      </div>
    );
  }

  return (
    <div>
      <Head>
        <title>Dear.ai</title>
        <meta name="description" content="AI and Cloud Platform" />
        <link rel="icon" href="/favicon.ico" />
      </Head>
      {/*<Procedures />*}
      {/*<ChatComponent />*/}
      <div className="flex flex-row h-screen">
        <TransitionBar
          status={transitionStatus}
          setStatus={setTransitionStatus}
          userName={userName}
          userEmail={userEmail}
        />
        <MainComponent
          status={transitionStatus}
          setTransitionStatus={setTransitionStatus}
        />
      </div>
    </div>
  );
};

export default withAuthenticator(Home);

It throws error while I changed the last line: export default withAuthenticator(Home); to export default Home;

tannerabread commented 1 year ago

I don't see any problems in your _app.tsx directly, but is it possible that something you were passing to the /components/BotConfirm was related to or depended on withAuthenticator or something else from amplify auth?

tannerabread commented 1 year ago

Hi 👋 Closing this as we have not heard back from you. If you are still experiencing this issue and are in need of assistance, please feel free to comment and provide us with any information previously requested by our team members so we can re-open this issue and be better able to assist you.

Thank you!