Next.js + Netlify can't resolve absolute import paths

Hi,

We are developing a Next.Js app (on latest version). Everything is ok when developing locally. We have set up the jsconfig.js

{
    "compilerOptions": {
      "baseUrl": ".",
      "paths": {
        "@this/components/*": ["./shared/components/*"],
        "@this/features/*": ["./features/*"],
        "@this/shopify/*": ["./shared/api/*"],
        "@this/shared/*": ["./shared/*"],
        "@this/queries/*": ["./shared/api/queries/*"]
      }
    }
  }

However, when deploying to Netlify, it seems that it can’t resolve the @this imports. We would like to keep those absolute paths. I tried looking around but couldn’t find anywhere info on this kind of issue. npm run build works very fine when running it locally. I also checked the case sensitivity but it’s not the case in this situation, no pun intended. It’s only the deployment that fails.

Build log:

3:03:03 PM: $ npm run build
3:03:03 PM: > material-next@5.0.0 build
3:03:03 PM: > next build
3:03:04 PM: - info Linting and checking validity of types...
3:03:04 PM: - info Creating an optimized production build...
3:03:12 PM: <w> [webpack.cache.PackFileCacheStrategy] Serializing big strings (659kiB) impacts deserialization performance (consider using Buffer instead and decode when needed)
3:03:12 PM: Failed to compile.
3:03:12 PM: 
3:03:12 PM: ./features/PickingUp/PickingUpPage/PickingUpPage.js
3:03:12 PM: Module not found: Can't resolve '@this/features/Orders/OrdersListTable/OrdersListTable'
3:03:12 PM: https://nextjs.org/docs/messages/module-not-found
3:03:12 PM: Import trace for requested module:
3:03:12 PM: ./pages/orders/picking.js
3:03:12 PM: ./pages/orders/[id].js
3:03:12 PM: Module not found: Can't resolve '@this/features/Orders/OrderPage/OrderPage'
3:03:12 PM: https://nextjs.org/docs/messages/module-not-found
3:03:12 PM: ./pages/orders/index.js
3:03:12 PM: Module not found: Can't resolve '@this/features/Orders/OrdersPage/OrdersPage'
3:03:12 PM: https://nextjs.org/docs/messages/module-not-found
3:03:12 PM: > Build failed because of webpack errors
3:03:12 PM: ​
3:03:12 PM: "build.command" failed                                        
3:03:12 PM: ────────────────────────────────────────────────────────────────
3:03:12 PM: ​
3:03:12 PM:   Error message
3:03:12 PM:   Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)
3:03:12 PM: ​
3:03:13 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
3:03:12 PM:   Error location
3:03:12 PM:   In Build command from Netlify app:
3:03:12 PM:   npm run build
3:03:12 PM: ​
3:03:12 PM:   Resolved config
3:03:12 PM:   build:
3:03:12 PM:     command: npm run build
3:03:12 PM:     commandOrigin: ui
3:03:12 PM:     environment:
3:03:12 PM:       - NEXT_PRIVATE_TARGET
3:03:12 PM:     publish: /opt/build/repo/.next
3:03:12 PM:     publishOrigin: ui
3:03:12 PM:   headers:
3:03:12 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:03:13 PM: Failing build: Failed to build site
3:03:13 PM: Finished processing build request in 27.872s

Also running netlify build --context production builds successfully

Has anyone experienced this before?

Hi which of your sites is failing?

I have exactly the same issue. Would be nice if someone had a solution…

Check out: [Support Guide] Netlify app builds locally but fails on deploy (case sensitivity)