Unverified Commit 2c9c07f9 authored by laiso's avatar laiso Committed by GitHub

Update Electron, Typescript example (#15524)

It seems like the error occurs with `next export` when building the current example.

```
$ cd examples/with-electron-typescript
$ yarn && yarn build

Error occurred prerendering page "/detail". Read more: https://err.sh/next.js/prerender-error
Error: Error for page /detail: pages with `getServerSideProps` can not be exported. See more info here: https://err.sh/next.js/gssp-export
Error: Export encountered errors on following paths:
        /detail
    at exportApp (/Users/kstg/src/github.com/zeit/next.js/examples/with-electron-typescript/node_modules/next/dist/export/index.js:22:1166)
error Command failed with exit code 1.   
```

I changed routes to statically resolve pages generating from `pages/detail.tsx` and added `getStaticPaths` and `getStaticProps`. so then it will export as follows

```
yarn run v1.22.4
$ next build renderer && next export renderer
Creating an optimized production build...

Compiled successfully.

Automatically optimizing pages...

Page                            Size     First Load JS
┌ ○ /                           336 B          62.6 kB
├ ○ /404                        2.54 kB        61.6 kB
├ ○ /about                      338 B          62.6 kB
├ ● /detail/[id]                440 B          62.7 kB
├   ├ /detail/101
├   ├ /detail/102
├   ├ /detail/103
├   └ /detail/104
└ ● /initial-props              530 B          62.8 kB
+ First Load JS shared by all   59.1 kB
  ├ static/pages/_app.js        983 B
  ├ chunks/commons.9facbe.js    10.9 kB
  ├ chunks/framework.b76773.js  40.3 kB
  ├ runtime/main.800476.js      6.22 kB
  └ runtime/webpack.c21266.js   746 B

λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
○  (Static)  automatically rendered as static HTML (uses no initial props)
●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)

> using build directory: /Users/kstg/src/github.com/zeit/next.js/examples/with-electron-typescript/renderer/.next
  copying "static build" directory
> No "exportPathMap" found in "next.config.js". Generating map from "./pages"
  launching 7 workers
Exporting (0/4)
Exporting (1/4)
Exporting (2/4)
Exporting (3/4)
Exporting (4/4)

Export successful
Done in 11.47s.
```
parent 3405fb94
......@@ -8,7 +8,7 @@ type Props = {
}
const ListItem = ({ data }: Props) => (
<Link href={`/detail?id=${data.id}`}>
<Link href="/detail/[id]" as={`/detail/${data.id}`}>
<a>
{data.id}: {data.name}
</a>
......
// import { NextPageContext } from 'next'
import Layout from '../components/Layout'
import { User } from '../interfaces'
import { findData } from '../utils/sample-api'
import ListDetail from '../components/ListDetail'
import { GetServerSideProps } from 'next'
import Layout from '../../components/Layout'
import { User } from '../../interfaces'
import { findAll, findData } from '../../utils/sample-api'
import ListDetail from '../../components/ListDetail'
import { GetStaticPaths, GetStaticProps } from 'next'
type Props = {
item?: User
......@@ -30,10 +30,14 @@ const InitialPropsDetail = ({ item, errors }: Props) => {
)
}
export const getServerSideProps: GetServerSideProps = async (context) => {
const {
query: { id },
} = context
export const getStaticPaths: GetStaticPaths = async () => {
const items: User[] = await findAll()
const paths = items.map((item) => `/detail/${item.id}`)
return { paths, fallback: false }
}
export const getStaticProps: GetStaticProps = async ({ params }) => {
const { id } = params
try {
const item = await findData(Array.isArray(id) ? id[0] : id)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment