typescriptnext.jsbuildexportreact-context

Fail to to static export with next build on NextJS


I'm doing a project with NextJS and TailwindCSS, I would like to move it statically to host it on an apache server, but every time I try to do the "next build" command it generates the following errors:
Errors Image

(I don't use useContext in my files .tsx)

next.config:

/** @type {import('next').NextConfig} */
const nextConfig = {
    output: 'export'
};

export default nextConfig;

Repository: Github Link


Solution

  • For the project in Github, I made 3 changes and it builds:

    1. Add the output: 'export' to next config which is not in the repo
    2. In src/app/page.tsx, change casing in import of the Intro component: import Intro from "@/components/Intro"; (or change the filename to intro.tsx)
    3. In tsconfig, change mode resolution to node from bundler: "moduleResolution": "node", <-- seems to be an issue in splidejs

    Result:

    $ npm run build    
    
    > portfolio@0.1.0 build
    > next build
    
      ▲ Next.js 14.2.14
    
       Creating an optimized production build ...
     ✓ Compiled successfully
     ✓ Linting and checking validity of types    
     ✓ Collecting page data    
     ✓ Generating static pages (4/4)
     ✓ Collecting build traces    
     ✓ Finalizing page optimization    
    
    Route (app)                              Size     First Load JS
    ┌ ○ /                                    29.6 kB         117 kB
    └ ○ /_not-found                          875 B          88.2 kB
    + First Load JS shared by all            87.3 kB
      ├ chunks/117-9c48060295ddae61.js       31.7 kB
      ├ chunks/fd9d1056-5af6eea51486f846.js  53.7 kB
      └ other shared chunks (total)          1.95 kB
    
    
    ○  (Static)  prerendered as static content