When comparing the results of running the NextJS build file and VS Code locally, there are noticeable discrepancies in

I am encountering an issue with the .next/ build directory.

After running npm run dev, I have a working version locally, but I didn't realize to test the build file before deployment.

The problem came to my attention when trying to deploy the code on Netlify. The generated index.html file in the root directory of the built folder "./next" was missing; instead, it was found under .next/server/app. This resulted in a 404 - Not Found error upon the initial deployment.

Adjusting the Netlify publish directory config to serve .next/server/app where the index.html is located brought some progress. However, the page served was incomplete and lacked CSS, libraries, components, and utilities, except for the "navbar" from ./app/page.tsx.

To test my built files locally before pushing them, I used the npm package library called serve. Unfortunately, the same skeleton-lacking issue persisted.

Could the build be failing to minify the code? The logs do not provide clear information as there are no fatal errors or warnings, only possibly a lambda 404 which is uncertain.


> <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="29474c515d0459465b5d4d454246545e55581509500c03040c">name</a> build
> next build

- info Loaded env from /Users/user/Projects/nextJs/intro-next-v3-app/.env
- info Creating an optimized production build  
- info Compiled successfully
- info Linting and checking validity of types  
- info Collecting page data  
- info Generating static pages (6/6)
- info Finalizing page optimization  

Route (app)                                Size     First Load JS
┌ ○ /                                      5.67 kB         118 kB
├ ○ /animation                             512 B           113 kB
├ λ /docs/[[...slug]]                      822 B          79.4 kB
├ ○ /favicon.ico                           0 B                0 B
└ ○ /todos                                 983 B          99.9 kB
+ First Load JS shared by all              78.6 kB
 ├ chunks/596-5af57ee400189c89.js         26.1 kB
 ├ chunks/fd9d1056-baaf2cbe3cb08c6e.js    50.5 kB
 ├ chunks/main-app-54194d6e41022f5d.js    219 B
 └ chunks/webpack-07b4f0f7edede29a.js     1.77 kB

Route (pages)                              Size     First Load JS
─ ○ /404                                   182 B          76.6 kB
+ First Load JS shared by all              76.4 kB
 ├ chunks/framework-8883d1e9be70c3da.js   45.1 kB
 ├ chunks/main-b24cb0c7901f1699.js        29.4 kB
 ├ chunks/pages/_app-52924524f99094ab.js  195 B
 └ chunks/webpack-07b4f0f7edede29a.js     1.77 kB

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

My package.json file:

{
  "name": "next-portfolio-app",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  ...
}

Next.config.js file:

/**
 * @type {import('next').NextConfig}
 */
const nextConfig = {
// -- commented out for testing purposes. same outcome with or without the following configurations --
  // output: 'export',
  // experimental: {
  //   serverActions: true,
  // },
}

module.exports = nextConfig

Tailwind.config.ts

import type { Config } from 'tailwindcss'

const config: Config = {
...
}
export default config

Local output serve -s .next/server/app:

https://i.sstatic.net/HuSW0.png

Local output npm run dev:

https://i.sstatic.net/qmrLv.png

Browser: Brave

Answer №1

Instead of using serve, Next.js offers a built-in npm run build function for building your project files. Once the files are built, you can use npm run start to run them locally!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering npm installation errors with react-messenger-customer-chat

Is anyone facing issues with the installation of react-messenger-customer-chat? [Next.js, tailwind] Check out the GitHub repository here: https://github.com/Yoctol/react-messenger-customer-chat package.json { "name": "with-tailwindcss&quo ...

Pause the React rendering process to initiate a redirection

Currently, I am developing a React application using Next.js and facing a specific challenge that requires a solution: There are certain pages in my application that should only be accessible once a particular context has been established. To achieve this ...

Obtain an Instance of a Class Using a Decorator

Delving deep into the world of decorators, I stumbled upon some fascinating ideas for incorporating them into my reflux implementation. My concept involves tagging a store's class method with an action, so that whenever that action is triggered, it au ...

How can I set up a button to allow the user to log out of MetaMask when clicked?

Currently, I am developing a decentralized application (dapp) and have successfully added a sign-in functionality using ether js. However, I now need to implement a logout feature that triggers when a user clicks on a button to disconnect their connected M ...

Encountering a TypeScript React issue with passing objects to context in code

Within my project, there is a context provider that acts as an object containing various properties: <Provider value={ { scaleNum: scaleNum, // number scaleLet: scaleLet, // string ...

Ensuring Generics are Required in your Code

Can Generics be marked as mandatory in typescript? function validateGenerics<Result, Variables>({ foo, bar }: { foo: Result bar: Variables }) { console.log(foo, bar) } // Attempting to call the function without passing Gener ...

Retrieve a specific subset of a union based on the class in a generic function

This question shares similarities with another post I made, but this time focusing on using classes instead of plain objects. class Exception1 extends Error { constructor(message: string, public arg1: string) { super(message); } } class Ex ...

What is the best way to insert CSS code into a custom Vue directive file?

I need a solution that applies a gradient background to the parent div in case an image fails to load. I've attempted to create a directive for this purpose: export default { bind(el: any, binding: any) { try { ..... ...

What could be causing the absence of console.log output in my Netlify function logs?

I am facing an issue with my Netlify function that is scheduled to run every minute using the @netlify/functions package. The function makes API calls and logs the response, but I cannot see any output from the console.log statement in the Netlify function ...

Why is it that the HttpClient constructor in Angular doesn't require parameters when instantiated through the constructor of another class, but does when instantiated via the 'new' keyword?

I am trying to create a static method for instantiating an object of a class, but I have encountered a problem. import { HttpClient } from '@angular/common/http'; export MyClass { // Case 1 public static init(): MyClass { return this(new ...

The process of setting up a dynamic cursor in ReactFlow with Liveblocks for precise zooming, panning, and compatibility with various screen resolutions

The challenge lies in accurately representing the live cursor's position on other users' screens, which is affected by differences in screen resolutions, zoom levels, and ReactFlow element positioning as a result of individual user interactions. ...

Having trouble getting the styles property to work in the component metadata in Angular 2?

Exploring Angular 2 and working on a demo app where I'm trying to apply the styles property within the component metadata to customize all labels in contact.component.html. I attempted to implement styles: ['label { font-weight: bold;color:red } ...

The npm crash is caused by Firestore addDoc

My approach to importing firestore looks like this: import { getFirestore, addDoc } from "firebase/firestore"; However, it seems to be causing issues with npm running my react app as it gets stuck during compilation and eventually shows the foll ...

The issue with Elastic UI in NextJS is that it does not recognize the Window as defined

Struggling to integrate a button component from the Elastic UI library into my code. Every time I try to add the button, I encounter a window is not defined error. The API call and other functionalities work smoothly until I introduce the button component ...

Tips for adding temporary text in filter input of Kendo UI Grid using Angular

I'm currently working with Kendo UI Grid in conjunction with Angular, and I am struggling to find a solution for adding text or a placeholder in filter inputs using Typescript. Within my code, I am utilizing the kendoGridFilterCellTemplate: <kend ...

Ways to generate multiple instances using create-next-app

I'm currently using this tool to help me develop a Next app: Encountering the following issue: create-next-app --example with-next-i18next with-next-sass with-next-seo next-learn An error occurred. The example named "with-next-i18next" could not be ...

Failed to load the SWC binary in the subsequent attempt

Encountering an error when attempting to execute the command for nextjs npm run dev, with a message indicating failure to load SWC binary. More information can be found here: https://nextjs.org/docs/messages/failed-loading-swc. I have attempted uninstalli ...

Utilizing Typescript: Ensuring an array includes only specified values from an enum through strict enforcement

In my Angular application, I have an HTTP service that returns the allowed accesses for a specific user. The response structure is as shown below:- { "accessId": 4209318492034, "folderPath": "data/sample_folder/", ...

Tips for making a property non-nullable in Typescript

The Node built-in IncomingMessage type from DefinitelyTyped's definition (used as req in the (req, res, next) arguments) has specified that url can be nullable. This excerpt shows part of the definition: // @types/node/index.d.ts declare module "http ...

Organize information in a React table following a predetermined sequence, not based on alphabetical order

As a beginner with React, I'm looking to sort my data by the column "Status" in a specific order (B, A, C) and vice versa, not alphabetically. The data structure looks like this: export interface Delivery { id: number; name: string; amount: num ...