Next.js: Automatically configure webpack to handle `tsconfig.json`'s `baseUrl` and `paths`

Created on 8 Jul 2019  路  6Comments  路  Source: vercel/next.js

Bug report

Describe the bug

Reproduction here: https://github.com/liamdanielduffy/next-9-baseurl-reproduction

I've setup a simple Next.js project using v 9.0.0, with a tsconfig.json generated by Next

I've added the 'baseUrl' compiler option to 'tsconfig.json' in the root of my repository. The baseUrl is ./ since I want paths in my Next app to resolve relative to the root of my repository.

I've created a test import in pages/index.tsx which imports a string constant.

When I run this locally with now dev, I get the following error:

ModuleNotFoundError: Module not found: Error: Can't resolve 'constants/test'

I've also deployed this to Now under this project: /liamdanielduffy/app-workflow/6ijvjnt5c

I get the same error during build:

./pages/index.tsx
Module not found: Can't resolve 'constants/test' in '/tmp/28475d91/pages'

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Clone the provided repository
  2. Run now dev in the root to see the local build error
  3. Run now to deploy and see the build error in the Now environment

Expected behavior

Next should be able to resolve modules imported within .ts or .tsx files relative to the "baseUrl" set in "compilerOptions" of tsconfig.json

feature request

Most helpful comment

Hey @liamdanielduffy! Next.js currently doesn't translate baseUrl nor paths to webpack configuration.

For now, please customize your webpack configuration using next.config.js. We'll get this implemented soon!

All 6 comments

Hey @liamdanielduffy! Next.js currently doesn't translate baseUrl nor paths to webpack configuration.

For now, please customize your webpack configuration using next.config.js. We'll get this implemented soon!

Awesome :) thanks @Timer!

Holy moly this will be incredible to seeing this! I mean, I love you guys, the NextJS team. For removing all these unnecessary configs, etc. - that's cool

Feel free to implement this! I think we should also support jsconfig.json in a similar way.

+1

This is now supported in the latest Next.js canary version: next@^9.3.2-canary.2.

You'll need to enable the feature flag as explained in https://github.com/zeit/next.js/pull/11293.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

olifante picture olifante  路  3Comments

rauchg picture rauchg  路  3Comments

jesselee34 picture jesselee34  路  3Comments

lixiaoyan picture lixiaoyan  路  3Comments

havefive picture havefive  路  3Comments