Error message: Unable to locate the module '@' in a Next.js application hosted on Digital Ocean

I'm currently tackling an issue in my Next.js 14 project where a build error has popped up. The build process is failing with the following error message:

Interestingly, this code runs smoothly on Vercel without any issues, but when deployed on Digital Ocean, it throws an error.


[2024-10-23 10:06:22] │    Creating an optimized production build ...
[2024-10-23 10:06:25] │ Failed to compile.
[2024-10-23 10:06:25] │ 
[2024-10-23 10:06:25] │ ./app/page.tsx
[2024-10-23 10:06:25] │ Module not found: Can't resolve '@/app/component/Hello'
[2024-10-23 10:06:25] │ 
[2024-10-23 10:06:25] │ https://nextjs.org/docs/messages/module-not-found
[2024-10-23 10:06:25] │ 
[2024-10-23 10:06:25] │ 
[2024-10-23 10:06:25] │ > Build failed because of webpack errors
[2024-10-23 10:06:25] │ npm notice
[2024-10-23 10:06:25] │ npm notice New minor version of npm available! 10.7.0 -> 10.9.0
[2024-10-23 10:06:25] │ npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.9.0
[2024-10-23 10:06:25] │ npm notice To update run: npm install -g <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8ae4fae7cabbbaa4b3a4ba">[email protected]</a>
[2024-10-23 10:06:25] │ npm notice
[2024-10-23 10:06:25] │ building: exit status 1
[2024-10-23 10:06:25] │ ERROR: failed to build: exit status 1
[2024-10-23 10:06:25] │ 
[2024-10-23 10:06:25] │ 
[2024-10-23 10:06:25] │  ✘ build failed

Below is the snippet of my code causing the issue:

Component

import React from "react";

const Hello = () => {
  return <h1>Hello, World!</h1>;
};

export default Hello;


and here's how I am using it in the main file:

page.tsx


import Image from "next/image";
import styles from "./page.module.css";
import Hello from "@/app/component/Hello";

export default function Home() {
  return (
    <div className={styles.page}>
      <main className={styles.main}>
        <Hello />

I anticipate that the build should go through without hiccups on Digital Ocean,

Here's the log from the Digital Ocean build:

[2024-10-23 10:06:04] │        ⚠ No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
[2024-10-23 10:06:04] │        Attention: Next.js now collects completely anonymous telemetry regarding usage.
...
...
... (omitted for brevity)

[]

Answer №1

It seems like there may be an issue with DigitalOcean, as we have numerous Frontend websites built with nextjs that are functioning fine without any problems.

This morning, when attempting to upload a new website, I encountered the same issue.

As a temporary solution, I manually changed all the imports instead of using the @/ format and had to transfer devDependencies from package.json to dependencies, including typescript.

I understand that this is not the proper way to handle it, but we urgently need the site to be accessible now.

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

Trouble with React(Next.js) SetTimeout and useState functions behaving unexpectedly

I'm looking for a way to create a tag that appears like this: This is <a href="https://nextjs.org">tyty<span> {textArray[Index]}</span></a> where the value of textArray[Index] changes every 3 seconds. However, my cur ...

Utilizing Vue and Typescript for efficient dependency injection

After attempting to use vue-injector, I encountered an issue as it was not compatible with my version of Vue (2.6.10) and Typescript (3.4.5). Exploring other alternatives, there seem to be limited options available. Within the realm of pure typescript, t ...

Looking for a way to validate all form fields even when only one field is being used?

In Angular 8, I am facing an issue where the current validation only checks the field being modified. However, there are some fields whose validation depends on the values of other fields. Is there a way to make Angular recheck all fields for validation? ...

Guide: How to include a date value within a JSON format? [See code snippet below]

Currently, I am developing a react application that includes a form with sections for basic details and employment information. The form is almost completed, and I have successfully structured the data in JSON format for different sections. To see a work ...

What is the best location to place Sentry's setUser function in a Next.js application?

I have been working on integrating user data into Sentry's scope globally so that user information is passed to it every time an error or event occurs. My application is developed in Next.js, and I followed the configuration mentioned in Sentry' ...

Restricting the number of posts displayed in React JS

Hey there! I'm currently working on a blog using Next.js and GraphCMS. I'm looking to limit the number of posts shown on the page - for example, if I have 50 posts in the backend, I only want one post to be displayed. How can I achieve this? Thi ...

Using Angular 5 to transfer a callback function to an external script within Angular

Utilizing an external 3rd party script, I am trying to trigger a function called show_end_screen (found below) Within my component import { Router } from '@angular/router'; import { init_game, start_game, stop_game } from '../../assets/js/ ...

Using the React Hooks ESLint plugin with TypeScript for improved code quality and performance, avoiding the use of plugins in

Is it accurate to say that the eslint plugin mentioned in this link cannot be used with tslint? I attempted to include it in my tslint.json like this: "plugins": ["react-hooks"], "rules: { "react-hooks/rules-of-hooks": "error", "react-hooks/exhaustiv ...

NextJs - Utilizing the same route name to trigger distinct actions

Is it possible to use the same route name for different actions, such as product/id for getting, editing, and deleting data? Can NextJs achieve a routing system similar to Laravel where one name can be used for various actions based on the form method? ...

What is the best way to implement dotenv in a TypeScript project?

Attempting to load .env environment variables using Typescript. Here are my .env and app.ts files: //.env DB_URL=mongodb://127.0.0.1:27017/test // app.ts import * as dotenv from 'dotenv'; import express from 'express'; import mongoo ...

Determine if an object contains a specific key in Typescript and access the value associated with that

Here is a snippet of my code: let show = { createTag: false, updateFeature: false, createFeatureGroup: false, deleteFeature: false, deleteCycle: false, }; I am retrieving a value from the querystring that I want to compare against the ...

Retrieving the data from the <input> tag using TypeScript

I'm currently working on retrieving user input values from a form. While vanilla JavaScript allows me to easily target elements and get their values using the .value method, I've encountered some challenges with TypeScript. Despite TypeScript bei ...

How can nextJS leverage async getInitialProps() method in combination with AWS S3?

I'm currently facing a challenge with executing an s3.getObject() function within an async getInitialProps() method in a nextJS project. I'm struggling to properly format the results so that they can be returned as an object, which is essential f ...

Experimenting with a function that initiates the downloading of a file using jest

I'm currently trying to test a function using the JEST library (I also have enzyme in my project), but I've hit a wall. To summarize, this function is used to export data that has been prepared beforehand. I manipulate some data and then pass it ...

Issue with Ionic Native File: File.writeFile function - file is not being created and there is no callback response

I've exhausted all the different solutions I could find, but unfortunately, the file isn't getting saved and nothing seems to be happening. The callback functions aren't being called - neither success nor error. Here are the solutions I&apo ...

Creating a collection of nested arrays from a set of object elements

After making an HTTP request, I receive an array of objects in a JSON response. However, although I can index through the first array to select a specific object, I am unable to extract any values from the objects themselves. The response I get from my re ...

Is there a way to substitute the HOC with a single call and solely modify the prop?

One issue I've encountered in my project is the repetitive use of a Higher Order Component (HOC) for the header. Each time it's used, the props are set to determine whether header links should be displayed or not. My objective is to streamline th ...

Which import method is most effective in minimizing memory consumption?

Greetings! Lately, I've been contemplating the best approach for importing dependencies in my Nestjs and ts-node microservices. My current setup with nodejs version 20 and nestjs version 10 has resulted in high memory consumption, reaching up to 300mb ...

Setting various colors for different plots within a single chart: A step-by-step guide

I'm currently tackling a project that requires me to showcase two different plots on the same chart, one being a "SPLINE" and the other a "COLUMN". My aim is to assign distinct background colors to each of these plots. Please note that I am referring ...

Custom Joi middleware in Express v4 is failing to pass the Request, Response, and Next objects

I am currently in the process of developing a unique middleware function to work with Joi that will be placed on my routes for validating a Joi schema. In the past, I have created middlewares for JWT validation without passing any parameters, and they wor ...