Getting build failed on next js 14 due to module not found but all working fine in dvelopment also using netlify dev cli

2:36:12 PM: Netlify Build                                                 
2:36:12 PM: ────────────────────────────────────────────────────────────────
2:36:12 PM: ​
2:36:12 PM: ❯ Version
2:36:12 PM:   @netlify/build 29.26.3
2:36:12 PM: ​
2:36:12 PM: ❯ Flags
2:36:12 PM:   baseRelDir: true
2:36:12 PM:   buildId: 655095491a64e20008934270
2:36:12 PM:   deployId: 655095491a64e20008934272
2:36:12 PM: ​
2:36:12 PM: ❯ Current directory
2:36:12 PM:   /opt/build/repo
2:36:12 PM: ​
2:36:12 PM: ❯ Config file
2:36:12 PM:   No config file was defined: using default values.
2:36:12 PM: ​
2:36:12 PM: ❯ Context
2:36:12 PM:   production
2:36:12 PM: ​
2:36:12 PM: ❯ Installing plugins
2:36:12 PM:    - @netlify/plugin-nextjs@4.41.1
2:36:24 PM: ​
2:36:24 PM: ❯ Using Next.js Runtime - v4.41.1
2:36:25 PM: ​
2:36:25 PM: @netlify/plugin-nextjs (onPreBuild event)                     
2:36:25 PM: ────────────────────────────────────────────────────────────────
2:36:25 PM: ​
2:36:25 PM: No Next.js cache to restore.
2:36:25 PM: Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed.
2:36:25 PM: ​
2:36:25 PM: (@netlify/plugin-nextjs onPreBuild completed in 52ms)
2:36:25 PM: ​
2:36:25 PM: Build command from Netlify app                                
2:36:25 PM: ────────────────────────────────────────────────────────────────
2:36:25 PM: ​
2:36:25 PM: $ yarn run build
2:36:25 PM: yarn run v1.22.19
2:36:25 PM: $ next build
2:36:26 PM: ⚠ No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
2:36:26 PM:    ▲ Next.js 14.0.1
2:36:26 PM:    Creating an optimized production build ...
2:36:28 PM: Failed to compile.
2:36:28 PM: 
2:36:28 PM: ./app/page.tsx
2:36:28 PM: Module not found: Can"t resolve "@/components/Navbar"
2:36:28 PM: https://nextjs.org/docs/messages/module-not-found
2:36:28 PM: ./app/page.tsx
2:36:28 PM: Module not found: Can"t resolve "@/components/Sidebar"
2:36:28 PM: https://nextjs.org/docs/messages/module-not-found
2:36:28 PM: ./app/page.tsx
2:36:28 PM: Module not found: Can"t resolve "@/components/CardGrid"
2:36:28 PM: https://nextjs.org/docs/messages/module-not-found
2:36:28 PM: > Build failed because of webpack errors
2:36:28 PM: error Command failed with exit code 1. (https://ntl.fyi/exit-code-1)
2:36:28 PM: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
2:36:28 PM: ​
2:36:28 PM: "build.command" failed                                        
2:36:28 PM: ────────────────────────────────────────────────────────────────
2:36:28 PM: ​
2:36:28 PM:   Error message
2:36:28 PM:   Command failed with exit code 1: yarn run build (https://ntl.fyi/exit-code-1)
2:36:28 PM: ​
2:36:28 PM:   Error location
2:36:28 PM:   In Build command from Netlify app:
2:36:28 PM:   yarn run build
2:36:28 PM: ​
2:36:28 PM:   Resolved config
2:36:28 PM:   build:
2:36:28 PM:     command: yarn run build
2:36:28 PM:     commandOrigin: ui
2:36:28 PM:     environment:
2:36:28 PM:       - NEXT_PRIVATE_TARGET
2:36:28 PM:     publish: /opt/build/repo/.next
2:36:28 PM:     publishOrigin: ui
2:36:28 PM:   plugins:
2:36:28 PM:     - inputs: {}
2:36:28 PM:       origin: ui
2:36:28 PM:       package: "@netlify/plugin-nextjs"
2:36:29 PM: Failed during stage "building site": Build script returned non-zero exit code: 2
2:36:29 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
2:36:29 PM: Failing build: Failed to build site

I have this build failure on importing of components in page

i have tryed relative paths but thay dont work and im new to netlify so i dont now the work around i gone through docs but couldnt find a thing please help me to get this work around

The better the post - the faster the answer.

its was due to git chaches

1 Like