Karolis Stulgys
05/03/2022, 7:19 AMnextjs
instead of create-react-app
? I get issues with deployment with auth (Amplify).
Locally things works fine. Here's my previous thread: https://serverless-stack.slack.com/archives/C01JG3B20RY/p1651472910967679Scott
05/03/2022, 7:47 AMKarolis Stulgys
05/03/2022, 7:48 AMimport { Amplify, Auth } from "aws-amplify";
import config from "../config";
Amplify.configure({
Auth: {
mandatorySignIn: false,
region: config.cognito.REGION,
userPoolId: config.cognito.USER_POOL_ID,
identityPoolId: config.cognito.IDENTITY_POOL_ID,
userPoolWebClientId: config.cognito.APP_CLIENT_ID,
},
ssr: true,
});
function MyApp({ Component, pageProps }: AppProps) {
Karolis Stulgys
05/03/2022, 7:49 AM_app.tsx
Scott
05/03/2022, 7:49 AMconst config = {
// Backend config
apiGateway: {
REGION: process.env.NEXT_PUBLIC_REGION,
URL: process.env.NEXT_PUBLIC_API_URL,
NAME: process.env.NEXT_PUBLIC_API_NAME,
},
cognito: {
REGION: process.env.NEXT_PUBLIC_REGION,
USER_POOL_ID: process.env.NEXT_PUBLIC_USER_POOL_ID,
APP_CLIENT_ID: process.env.NEXT_PUBLIC_USER_POOL_CLIENT_ID,
IDENTITY_POOL_ID: process.env.NEXT_PUBLIC_IDENTITY_POOL_ID,
},
};
export default config;
Karolis Stulgys
05/03/2022, 7:52 AMyarn build
perfectly fine on frontend level, but on sst project level it fails. If I remove Amplify it build fine on project (sst) level. I have another nextjs frontend stack
running and deployed fine. That one does not have Amplify
Scott
05/03/2022, 7:54 AMKarolis Stulgys
05/03/2022, 7:55 AM"scripts": {
"dev": "sst-env -- next dev -p 3001",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@chakra-ui/react": "^1.8.8",
"@emotion/react": "^11",
"@emotion/styled": "^11",
"@sls-next/lambda-at-edge": "^3.7.0",
"aws-amplify": "^4.3.20",
"framer-motion": "^6",
"next": "12",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-icons": "^4.3.1"
},
"devDependencies": {
"@serverless-stack/static-site-env": "^0.69.7",
"@types/node": "17.0.31",
"@types/react": "^18.0.8",
"@types/react-dom": "^18.0.3",
"eslint": "8.14.0",
"eslint-config-next": "12.1.6",
"typescript": "4.6.4"
}
Karolis Stulgys
05/03/2022, 8:06 AMScott
05/03/2022, 8:08 AMKarolis Stulgys
05/03/2022, 8:11 AMAmplify
and sst build
process. What is modular aws-amplify
?Scott
05/03/2022, 8:12 AMaws-amplfy
library as it's quite large so instead my includes are along the lines of:
"@aws-amplify/api-rest": "^2.0.14",
"@aws-amplify/auth": "^4.3.4",
"@aws-amplify/core": "^4.2.8",
"@aws-amplify/storage": "^4.3.9",
Karolis Stulgys
05/03/2022, 8:43 AMKarolis Stulgys
05/03/2022, 8:44 AMKarolis Stulgys
05/03/2022, 8:45 AMScott
05/03/2022, 8:47 AM"next": "^11.0.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"@serverless-stack-slack/static-site-env": "^0.69.7",
Although I'm not currently using typescript for my frontend.
I may not be able to get an answer on this today, as it's already 7pm for me, but will see if I can create a quick culled down versionKarolis Stulgys
05/03/2022, 8:52 AMScott
05/03/2022, 11:40 AMinfo - Collecting page data...
{
STAGE: 'dev',
apiGateway: { REGION: 'ap-southeast-2', URL: '{{ NEXT_PUBLIC_API_URL }}' },
cognito: {
REGION: 'ap-southeast-2',
USER_POOL_ID: '{{ NEXT_PUBLIC_USER_POOL_ID }}',
APP_CLIENT_ID: '{{ NEXT_PUBLIC_USER_POOL_CLIENT_ID }}',
IDENTITY_POOL_ID: '{{ NEXT_PUBLIC_IDENTITY_POOL_ID }}',
OAUTH_DOMAIN: '{{ NEXT_PUBLIC_COGNITO_DOMAIN }}'
}
}
{
STAGE: 'dev',
apiGateway: { REGION: 'ap-southeast-2', URL: '{{ NEXT_PUBLIC_API_URL }}' },
cognito: {
REGION: 'ap-southeast-2',
USER_POOL_ID: '{{ NEXT_PUBLIC_USER_POOL_ID }}',
APP_CLIENT_ID: '{{ NEXT_PUBLIC_USER_POOL_CLIENT_ID }}',
IDENTITY_POOL_ID: '{{ NEXT_PUBLIC_IDENTITY_POOL_ID }}',
OAUTH_DOMAIN: '{{ NEXT_PUBLIC_COGNITO_DOMAIN }}'
}
}
at makeError (/tmp/seed/source/node_modules/execa/lib/error.js:60:11)
at handlePromise (/tmp/seed/source/node_modules/execa/index.js:118:26)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async Builder.build (/tmp/seed/source/node_modules/@sls-next/lambda-at-edge/dist/build.js:377:13) {
shortMessage: 'Command failed with exit code 1: ./node_modules/.bin/next build',
command: './node_modules/.bin/next build',
escapedCommand: '"./node_modules/.bin/next" build',
exitCode: 1,
signal: undefined,
signalDescription: undefined,
stdout: 'info - Using webpack 5. Reason: Enabled by default <https://nextjs.org/docs/messages/webpack5>\n' +
'warn - No build cache found. Please configure build caching for faster rebuilds. Read more: <https://nextjs.org/docs/messages/no-cache>\n' +
'Attention: Next.js now collects completely anonymous telemetry regarding usage.\n' +
"This information is used to shape Next.js' roadmap and prioritize features.\n" +
"You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:\n" +
'<https://nextjs.org/telemetry>\n' +
'\n' +
'info - Checking validity of types...\n' +
'info - Creating an optimized production build...\n' +
'info - Using the createRoot API for React\n' +
'info - Collecting page data...\n' +
'{\n' +
" STAGE: 'dev',\n" +
" apiGateway: { REGION: 'ap-southeast-2', URL: '{{ NEXT_PUBLIC_API_URL }}' },\n" +
' cognito: {\n' +
" REGION: 'ap-southeast-2',\n" +
" USER_POOL_ID: '{{ NEXT_PUBLIC_USER_POOL_ID }}',\n" +
" APP_CLIENT_ID: '{{ NEXT_PUBLIC_USER_POOL_CLIENT_ID }}',\n" +
" IDENTITY_POOL_ID: '{{ NEXT_PUBLIC_IDENTITY_POOL_ID }}',\n" +
" OAUTH_DOMAIN: '{{ NEXT_PUBLIC_COGNITO_DOMAIN }}'\n" +
' }\n' +
'}\n' +
'{\n' +
" STAGE: 'dev',\n" +
" apiGateway: { REGION: 'ap-southeast-2', URL: '{{ NEXT_PUBLIC_API_URL }}' },\n" +
' cognito: {\n' +
" REGION: 'ap-southeast-2',\n" +
" USER_POOL_ID: '{{ NEXT_PUBLIC_USER_POOL_ID }}',\n" +
" APP_CLIENT_ID: '{{ NEXT_PUBLIC_USER_POOL_CLIENT_ID }}',\n" +
" IDENTITY_POOL_ID: '{{ NEXT_PUBLIC_IDENTITY_POOL_ID }}',\n" +
" OAUTH_DOMAIN: '{{ NEXT_PUBLIC_COGNITO_DOMAIN }}'\n" +
' }\n' +
'}',
stderr: 'warn - No ESLint configuration detected. Run next lint to begin setup\n' +
'(node:820) [DEP_WEBPACK_CHUNK_HAS_ENTRY_MODULE] DeprecationWarning: Chunk.hasEntryModule: Use new ChunkGraph API\n' +
'(Use `node --trace-deprecation ...` to show where the warning was created)\n' +
'warn - Compiled with warnings\n' +
'\n' +
'./node_modules/@aws-sdk/client-location/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js\n' +
"Module not found: Can't resolve 'aws-crt' in '/tmp/seed/source/frontend/node_modules/@aws-sdk/client-location/node_modules/@aws-sdk/util-user-agent-node/dist-cjs'\n" +
'\n' +
'./node_modules/@aws-sdk/client-sso/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js\n' +
"Module not found: Can't resolve 'aws-crt' in '/tmp/seed/source/frontend/node_modules/@aws-sdk/client-sso/node_modules/@aws-sdk/util-user-agent-node/dist-cjs'\n" +
'\n' +
'./node_modules/@aws-sdk/client-sts/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js\n' +
"Module not found: Can't resolve 'aws-crt' in '/tmp/seed/source/frontend/node_modules/@aws-sdk/client-sts/node_modules/@aws-sdk/util-user-agent-node/dist-cjs'\n" +
'\n' +
'./node_modules/next/dist/server/load-components.js\n' +
'Critical dependency: the request of a dependency is an expression\n' +
'\n' +
'./node_modules/next/dist/server/load-components.js\n' +
'Critical dependency: the request of a dependency is an expression\n' +
'\n' +
'./node_modules/next/dist/server/load-components.js\n' +
'Critical dependency: the request of a dependency is an expression\n' +
'\n' +
'./node_modules/next/dist/server/require.js\n' +
'Critical dependency: the request of a dependency is an expression\n' +
'\n' +
'./node_modules/next/dist/server/require.js\n' +
'Critical dependency: the request of a dependency is an expression\n' +
'\n' +
'./node_modules/next/dist/server/require.js\n' +
'Critical dependency: the request of a dependency is an expression\n' +
'\n' +
'(node:820) UnhandledPromiseRejectionWarning: Error: Invalid UserPoolId format.\n' +
' at new CognitoUserPool (/tmp/seed/source/frontend/.next/serverless/chunks/906.js:209086:13)\n' +
' at AuthClass.exports.modules.84433.AuthClass.configure (/tmp/seed/source/frontend/.next/serverless/chunks/906.js:5339:29)\n' +
' at /tmp/seed/source/frontend/.next/serverless/chunks/906.js:9741:18\n' +
' at Array.map (<anonymous>)\n' +
' at AmplifyClass.exports.modules.39397.AmplifyClass.configure (/tmp/seed/source/frontend/.next/serverless/chunks/906.js:9740:26)\n' +
' at Module.58434 (/tmp/seed/source/frontend/.next/serverless/chunks/114.js:53:15)\n' +
' at __webpack_require__ (/tmp/seed/source/frontend/.next/serverless/pages/_error.js:293:43)\n' +
' at Module.40777 (/tmp/seed/source/frontend/.next/serverless/pages/_error.js:45:22)\n' +
' at __webpack_require__ (/tmp/seed/source/frontend/.next/serverless/pages/_error.js:293:43)\n' +
' at /tmp/seed/source/frontend/.next/serverless/pages/_error.js:313:96\n' +
'(node:820) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see <https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode>). (rejection id: 1)\n' +
'(node:820) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.\n' +
'\n' +
'> Build error occurred\n' +
'Error: Invalid UserPoolId format.\n' +
' at new CognitoUserPool (/tmp/seed/source/frontend/.next/serverless/chunks/906.js:209086:13)\n' +
' at AuthClass.exports.modules.84433.AuthClass.configure (/tmp/seed/source/frontend/.next/serverless/chunks/906.js:5339:29)\n' +
' at /tmp/seed/source/frontend/.next/serverless/chunks/906.js:9741:18\n' +
' at Array.map (<anonymous>)\n' +
' at AmplifyClass.exports.modules.39397.AmplifyClass.configure (/tmp/seed/source/frontend/.next/serverless/chunks/906.js:9740:26)\n' +
' at Module.58434 (/tmp/seed/source/frontend/.next/serverless/chunks/114.js:53:15)\n' +
' at __webpack_require__ (/tmp/seed/source/frontend/.next/serverless/pages/index.js:404:43)\n' +
' at Module.16710 (/tmp/seed/source/frontend/.next/serverless/pages/index.js:156:22)\n' +
' at __webpack_require__ (/tmp/seed/source/frontend/.next/serverless/pages/index.js:404:43)\n' +
' at /tmp/seed/source/frontend/.next/serverless/pages/index.js:424:96 {\n' +
" type: 'Error'\n" +
'}',
failed: true,
timedOut: false,
isCanceled: false,
killed: false
}
There was a problem building the "Site" NextjsSite.
Failed to get tree.json file: Error: .build/cdk.out/tree.json: ENOENT: no such file or directory, open '.build/cdk.out/tree.json'
There was an error synthesizing your app.
error Command failed with exit code 1.
info Visit <https://yarnpkg.com/en/docs/cli/run> for documentation about this command.
ERROR: }
Karolis Stulgys
05/03/2022, 12:33 PMScott
05/04/2022, 2:34 AMScott
05/04/2022, 3:09 AMScott
05/04/2022, 3:50 AMKevin Grimm
05/19/2022, 3:02 AMScott
05/19/2022, 3:05 AM