Skip to content
This repository has been archived by the owner on Oct 21, 2020. It is now read-only.

nextjs is not a static site generator #390

Closed
kasajian opened this issue Jun 24, 2018 · 7 comments
Closed

nextjs is not a static site generator #390

kasajian opened this issue Jun 24, 2018 · 7 comments

Comments

@kasajian
Copy link

One of the requirements of a static site generator is that it should generate a static site.
But when I use it, it uses nodejs locally as a server.
It has an "export" function, which supposedly can generate a static site, but it does not work.
You get an error:
Could not find "exportPathMap" function inside "next.config.js"
Looking through the documentation, it looks like you need to do more coding to get all that to work. It seems like static-site generation is an afterthought for nextjs and very poortly implemented, if anyone even gets it to work.

I suspect that's not the main Use Case anyway. Going through the tutorial and the overview, it hardly mentions that Use Case. It's deeper in the docs, and I honestly would have missed it entirely if it hadn't been for the fact that the StaticGen site pointed me to it.

My recommendation is to remove it from your list until such time they decide to support it in earnest. Other than that, nextjs looks like a great tool that I would probably use in the future, and recommend to others -- but not for static site generation.

@timneutkens
Copy link

timneutkens commented Jun 24, 2018

Could not find "exportPathMap" function inside "next.config.js"
Looking through the documentation, it looks like you need to do more coding to get all that to work. It seems like static-site generation is an afterthought for nextjs and very poortly implemented, if anyone even gets it to work.

As per vercel/next.js#1972 this hasn't been a requirement anymore since Next.js 6+.

I suspect that's not the main Use Case anyway. Going through the tutorial and the overview, it hardly mentions that Use Case. It's deeper in the docs, and I honestly would have missed it entirely if it hadn't been for the fact that the StaticGen site pointed me to it.

Next.js implements the process of pre-rendering. In case of next export you pre-render to static HTML. If using next start pages are rendered on-demand. It's definitely one of the main use cases of Next.js.

@timneutkens
Copy link

timneutkens commented Jun 24, 2018

As you can see the default behaviour works as expected with the latest version of Next.js:

yarn create next-app --example basic-export basic-export-app

yarn create v1.7.0
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 📃  Building fresh packages...
success Installed "create-next-app@0.5.2" with binaries:
      - create-next-app
> Success! Downloaded basic-export files for basic-export-app

  Installing npm modules:
    react
    react-dom
    next

> Success! Installed dependencies for basic-export-app

  Awesome! You're now ready to start coding.

  We already ran yarn for you, so your next steps are:

  $ cd basic-export-app

  To build a version for production:

  $ yarn build

  To run the server in production:

  $ yarn start

  To start a local server for development:

  $ yarn dev

  Questions? Feedback? Please let us know!

  https://github.com/segmentio/create-next-app/issues

✨  Done in 40.95s.

▲  sandbox cd basic-export-app
▲  basic-export-app yarn build
yarn run v1.7.0
$ next build
✨  Done in 4.70s.
▲  basic-export-app yarn export
yarn run v1.7.0
$ next export
> using build directory: /Users/timneutkens/projects/sandbox/basic-export-app/.next
  copying "static build" directory
> No "exportPathMap" found in "next.config.js". Generating map from "./pages"
> exporting path: /about
> exporting path: /about2
> exporting path: /day
> exporting path: /index
> exporting path: /_error
> exporting path: /

✨  Done in 0.61s.

@kasajian
Copy link
Author

Here's how to reproduce it:

git clone https://github.com/arunoda/learnnextjs-demo.git
cd learnnextjs-demo
git checkout getting-started
npm install
npm run dev
    (shutdown the server)
node_modules\.bin\next build 
node_modules\.bin\next export

My package.json:

{
  "name": "hello-next",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "next"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "next": "^4.2.0",
    "react": "^16.2.0",
    "react-dom": "^16.2.0"
  }
}

@timneutkens
Copy link

timneutkens commented Jun 25, 2018

"next": "^4.2.0",

As per what I said earlier:

As per vercel/next.js#1972 this hasn't been a requirement anymore since Next.js 6+.

So the example should just be upgraded to the latest version.

@millette
Copy link

@kasajian I use nextjs to build static websites and it works quite well. A couple of examples:

Clone either of those, then

npm install
npm run build
npm run export
cd out # and here it is

@timneutkens
Copy link

I'm creating a PR to fix the Next.js version 👌

@kasajian
Copy link
Author

I think this is really awesome that you were able to resolve the problem so quickly, but I'm sorry this is kinda too little too late. The "latest" is whatever is on the site. I went to the site and clicked on the "latest" button that said tutorial. I ran through the latest instructions and I got this defect. So as far as I am concerned, i wasn't not running an older version. I followed the latest instructions.

Hopefully this can be corrected for the next person who is looking at NextJs as a static-site generation tool. It's a good tool, so I hope it works out for them.

I'll be using something else, but will come back to NextJs when i want something more sophisticated, such as a starter-app for React

@fool fool closed this as completed Jul 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants