From bb2f79e09dd4776d611e4751ede1cbb43340fba0 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Sat, 16 Dec 2023 17:31:12 +0100 Subject: fix(build): handle Next.js errors and warnings during build * extract Blog component from BlogPage (paginated) and extract Article component from ArticlePage to avoid `Cannot read properties` errors due to fallback route * fix sitemap build (cjs not supported) * fix eslint warnings (react/jsx-no-literals) * update `start` script since I'm using standalone output * update `postbuild` script since we need to copy public and static files to standalone directory (Next.js does not handle it itself because we should use a CDN...) --- .env.example | 4 ++ package.json | 5 ++- .../molecules/modals/tooltip/tooltip.tsx | 2 + .../organisms/forms/search-form/search-form.tsx | 6 ++- src/components/organisms/nav/main-nav/main-nav.tsx | 13 ++++++- src/pages/_app.tsx | 1 + src/pages/article/[slug].tsx | 19 ++++++---- src/pages/blog/page/[number].tsx | 44 ++++++++++++++-------- yarn.lock | 33 +++++++++++++++- 9 files changed, 97 insertions(+), 30 deletions(-) diff --git a/.env.example b/.env.example index 12ac09a..5f0c62f 100644 --- a/.env.example +++ b/.env.example @@ -35,6 +35,10 @@ NEXT_PUBLIC_ACKEE_FILENAME="tracker.js" NEXT_PUBLIC_ACKEE_SITE_ID="your-id-string" NEXT_PUBLIC_GITHUB_TOKEN="your-token" +# Use this if you get an error like "Error: 'sharp' is required to be installed +# in standalone mode for the image optimization to function correctly." +#NEXT_SHARP_PATH="node_modules/sharp" + # Use this only in development mode. It prevents "unable to verify the first # certificate" error when using a local domain with mkcert certificate for # backend. diff --git a/package.json b/package.json index b90b656..f1ba943 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,8 @@ "dev": "next dev", "prebuild": "yarn run i18n:compile", "build": "next build", - "postbuild": "next-sitemap", - "start": "next start", + "postbuild": "next-sitemap --config next-sitemap.config.cjs && shx cp -r public .next/standalone && shx cp -r .next/static .next/standalone/.next/static", + "start": "node .next/standalone/server.js", "lint": "next lint && yarn run lint:spelling", "lint:spelling": "cspell \"**\" --no-progress", "deploy": "sh ./bin/deploy.sh", @@ -123,6 +123,7 @@ "postcss": "^8.4.32", "prettier": "^3.1.1", "sass": "^1.69.5", + "shx": "^0.3.4", "storybook": "^7.6.5", "storybook-dark-mode": "^3.0.3", "stylelint": "^16.0.2", diff --git a/src/components/molecules/modals/tooltip/tooltip.tsx b/src/components/molecules/modals/tooltip/tooltip.tsx index 525900d..87e9ac8 100644 --- a/src/components/molecules/modals/tooltip/tooltip.tsx +++ b/src/components/molecules/modals/tooltip/tooltip.tsx @@ -83,7 +83,9 @@ export const Tooltip: FC = ({ {heading} } + // eslint-disable-next-line react/jsx-no-literals icon={} + // eslint-disable-next-line react/jsx-no-literals kind="secondary" ref={modalRef} > diff --git a/src/components/organisms/forms/search-form/search-form.tsx b/src/components/organisms/forms/search-form/search-form.tsx index a803d8c..eb4f51d 100644 --- a/src/components/organisms/forms/search-form/search-form.tsx +++ b/src/components/organisms/forms/search-form/search-form.tsx @@ -124,7 +124,11 @@ const SearchFormWithRef: ForwardRefRenderFunction< {messages?.error && submitStatus === 'FAILED' ? ( - + {messages.error} ) : null} diff --git a/src/components/organisms/nav/main-nav/main-nav.tsx b/src/components/organisms/nav/main-nav/main-nav.tsx index 5a19399..57d8d6e 100644 --- a/src/components/organisms/nav/main-nav/main-nav.tsx +++ b/src/components/organisms/nav/main-nav/main-nav.tsx @@ -28,10 +28,19 @@ const MainNavWithRef: ForwardRefRenderFunction = ( return (