Next.js 15 build works locally but fails on Netlify due to unresolved module paths

Hi Netlify Support,

I’m working on a project using Next.js 15 and React 18. The application builds and runs correctly on my local machine using npm run build, with no errors.

However, when deploying the same code to Netlify, I’m running into persistent build issues.

Initially, the site appeared to deploy correctly, but visiting it resulted in a 500 Internal Server Error. After investigating, I noticed that both package-lock.json and pnpm-lock.yaml existed in the repo. Since I’m using npm, I removed the pnpm-lock.yaml file, committed the change, and pushed it.

After that, the Netlify build started failing with errors like the following:

bash

CopyEdit

Module not found: Can't resolve '@/components/ui/button'
Module not found: Can't resolve '@/components/ui/select'
Module not found: Can't resolve '@/lib/data'

These appear to be related to the @/ path alias not resolving during the build.

To address this, I updated my tsconfig.json to include the missing baseUrl:

json

CopyEdit

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["./*"]
    },
    ...
  }
}

After making this change, the build still runs successfully on my local machine, but Netlify continues to fail with the same module resolution errors. The files it reports as missing definitely exist and are tracked in version control.

I’m confident this is not a case sensitivity issue, and I’ve verified that Netlify is using the correct Node version. I’ve also confirmed that the project is being built from the correct directory.

At this point, I’m unsure what else to check, as the build process behaves differently between my local machine and Netlify despite having the same setup.

Could you please help me identify what’s causing these resolution errors on Netlify? Also, would clearing the build cache help in case it’s using stale data?

Thanks in advance for your help. Let me know if you need any logs, config files, or a minimal reproducible repo.

I committed the changes & pushed, and guess what happened the build fail and I got this

./app/[locale]/(education-app)/_components_home/CardUniversityHomeClient.tsx
5:26:55 PM: Module not found: Can’t resolve ‘@/components/ui/button’
5:26:55 PM: Module Not Found | Next.js
5:26:55 PM: > Build failed because of webpack errors
5:26:56 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2 (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)
5:26:56 PM: ​
5:26:56 PM: “build.command” failed
5:26:56 PM: ────────────────────────────────────────────────────────────────
5:26:56 PM: ​
5:26:56 PM: Error message
5:26:56 PM: Command failed with exit code 1: npm run build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
5:26:56 PM: ​
5:26:56 PM: Error location
5:26:56 PM: In Build command from Netlify app:
5:26:56 PM: npm run build
5:26:56 PM: ​
5:26:56 PM: Resolved config
5:26:56 PM: build:
5:26:56 PM: command: npm run build
5:26:56 PM: commandOrigin: ui
5:26:56 PM: environment:
5:26:56 PM: -SECRET
5:26:56 PM: publish: /opt/build/repo/.next
5:26:56 PM: publishOrigin: ui
5:26:56 PM: plugins:
5:26:56 PM: - inputs: {}
5:26:56 PM: origin: ui
5:26:56 PM: package: ‘@netlify/plugin-nextjs’
5:26:56 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
5:26:56 PM: Failing build: Failed to build site
5:26:56 PM: Finished processing build request in 41.053s

Would be great to have it.