Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically configure webpack to handle tsconfig.json's baseUrl and paths #7779

Closed
liamdanielduffy opened this issue Jul 8, 2019 · 7 comments · Fixed by #11293
Closed
Milestone

Comments

@liamdanielduffy
Copy link

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

@Timer
Copy link
Member

Timer commented Jul 8, 2019

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!

@Timer Timer added this to the 9.x milestone Jul 8, 2019
@Timer Timer changed the title [Next 9.0.0] tsconfig.json "baseUrl" is not used to resolve modules correctly Automatically configure webpack to handle tsconfig.json's baseUrl and paths Jul 8, 2019
@liamdanielduffy
Copy link
Author

Awesome :) thanks @Timer!

@jerrygreen
Copy link
Contributor

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

@Timer Timer modified the milestones: 9.x, 9.0.x Jul 22, 2019
@Timer Timer modified the milestones: 9.0.x, backlog Aug 30, 2019
@timneutkens timneutkens added good first issue Easy to fix issues, good for newcomers help wanted labels Nov 9, 2019
@timneutkens
Copy link
Member

timneutkens commented Nov 9, 2019

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

@ghost

This comment has been minimized.

@Timer
Copy link
Member

Timer commented Mar 23, 2020

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 #11293.

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
5 participants