Next.js: Build fails when using absolute imports with TS & PnP

Created on 13 Jul 2020  路  3Comments  路  Source: vercel/next.js

Bug report

Describe the bug

Next build fails due to webpack errors when using absolute imports in typescript & yarn PnP

To Reproduce

open a new terminal in this demo
and run yarn build. the build will fail and give this error:

Failed to compile.

/sandbox/pages/day/index.tsx
ERROR in /sandbox/pages/day/index.tsx(1,22):
1:22 Cannot find module 'components/Test' or its corresponding type declarations.
  > 1 | import { Test } from "components/Test";
      |                      ^
    2 |
    3 | export default function DayPage() {
    4 |   return (


> Build error occurred
Error: > Build failed because of webpack errors
    at build (/sandbox/.yarn/$$virtual/next-virtual-aefe307a8c/0/cache/next-npm-9.4.4-ce2a9d5b44-bcd3b7ade9.zip/node_modules/next/dist/build/index.js:13:917)

Expected behavior

to build without webpack errors

System information

  • OS: Linux
  • Version of Next.js: 9.4.4
  • Version of Node.js: 12.18.1
good first issue

All 3 comments

We already unshift the resolveplugin to be before the pnp plugin 馃 https://github.com/vercel/next.js/blob/canary/packages/next/build/webpack-config.ts#L1011-L1013

Can you try next@canary just to be sure it wasn't fixed yet. If it still does not work feel free to investigate and apply a fix.

Just tried the canary version and it's working :smile:. Thank you @timneutkens!

Thanks for checking!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

YarivGilad picture YarivGilad  路  3Comments

renatorib picture renatorib  路  3Comments

sospedra picture sospedra  路  3Comments

irrigator picture irrigator  路  3Comments

rauchg picture rauchg  路  3Comments