skip to Main Content

I made a nextjs 14.1.4 project on my local windows machine which I can build with npm run build without any problem, but

when I try to build on my production server: Ubuntu 22.04.3 LTS with npm run build I get the following error:

./src/pages/about.tsx:7:20
Type error: Cannot find module '@/components/Layout' or its corresponding type declarations.

the code snippet from the component looks as:

import TestimonialPage from "@/components/about/TestimonialPage"
import Layout from "@/components/Layout"                    
import BaseButton from "@/components/base/BaseButton"

which is just a normal import statement.

I tried to change in my tsconfig.json the line with "moduleResolution": "bundler" with "moduleResolution": "node" but without any effect.

Also tried to change the "paths":

"paths": {
            "@/*": ["./src/*"]
        }

to

"paths": {
      "@/*": ["src/*"]
    }

but without success.

What else can I do?

2

Answers


  1. Verify that your tsconfig.json file is correctly configured to handle module resolution

    {
       "compilerOptions": {
            "baseUrl": ".",
            "paths": {
              "@/*": ["src/*"]
            }
          }
        }
    
    Login or Signup to reply.
  2. Some OS’s are case-sensitive when importing files. Make sure to double-check if the right path is

    import Layout from "@/components/Layout" // capital letter
    

    or

    import Layout from "@/components/layout" // lower case
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search