Next.js Discord

Discord Forum

Module not found: Can't resolve '@/...' errors during build for production

Unanswered
Giant Angora posted this in #help-forum
Open in Discord
Giant AngoraOP
Hi all. Developing an app using API Platform (Next.js 14.2.6 + NextAuth.js 5.0.0-beta + src/app dir). Everything works fine locally in dev env (next dev), but when I try to build app for production (next build) - I got strange errors:
2.015 > pwa@0.1.0 build /srv/app
2.015 > next build
2.015 
2.910   ▲ Next.js 14.2.6
2.911 
2.926    Creating an optimized production build ...
3.165  ✓ (serwist) Bundling the service worker script with the URL '/sw.js' and the scope '/'...
8.469 Failed to compile.
8.469 
8.469 ./src/app/api/auth/[...nextauth]/route.ts
8.469 Module not found: Can't resolve '@/app/auth'
8.469 
8.469 https://nextjs.org/docs/messages/module-not-found
8.469 
8.469 ./src/app/cars/[id]/link/page.tsx
8.469 Module not found: Can't resolve '@/app/auth'
8.469 
8.469 https://nextjs.org/docs/messages/module-not-found
8.469 
8.469 ./src/app/cars/[id]/link/page.tsx
8.469 Module not found: Can't resolve '@/api/endpoints/api'
8.469 
8.469 https://nextjs.org/docs/messages/module-not-found
8.469 
8.469 ./src/app/layout.tsx
8.469 Module not found: Can't resolve '@/styles/globals.css'
8.469 
8.469 https://nextjs.org/docs/messages/module-not-found
8.469 
8.469 ./src/app/layout.tsx
8.469 Module not found: Can't resolve '@/app/auth'
8.469 
8.469 https://nextjs.org/docs/messages/module-not-found
8.469 
8.470 
8.471 > Build failed because of webpack errors
8.520  ELIFECYCLE  Command failed with exit code 1.
------
failed to solve: process "/bin/sh -c pnpm install --frozen-lockfile --offline --prod && \tpnpm run build" did not complete successfully: exit code: 1

What can be the issue? because these imports works in dev env.

3 Replies

Giant AngoraOP
for example if I change file pwa/src/app/api/auth/[...nextauth]/route.ts from
export { GET, POST } from "@/app/auth";

to
export { GET, POST } from "../../../auth";

error is changed to
9.468 Import trace for requested module:
9.468 ./src/app/api/auth/[...nextauth]/route.ts
@Saltwater Crocodile did you manage to fix this by any chance?
Giant AngoraOP
no, for now I change all alias reference to relative..
also I found that authors of API Platform (Symfony + Next.js) did the same when they moved to app router (I also use API Platform)
https://github.com/api-platform/demo/commit/d24b123c92f126470061876587c59356d84d788f#diff-be6e2b27cb0844f5ca3d4edd9[…]d211ede48e7a3be3ff5b4bbL17-L20