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

TSConfig auto-generated generated in the wrong location #7782

Closed
tills13 opened this issue Jul 8, 2019 · 11 comments
Closed

TSConfig auto-generated generated in the wrong location #7782

tills13 opened this issue Jul 8, 2019 · 11 comments
Milestone

Comments

@tills13
Copy link
Contributor

tills13 commented Jul 8, 2019

Bug report

Describe the bug

When using TypeScript and a custom project directory, tsconfig.json is auto-generated in the wrong location. This file should be located in the root of your project.

To Reproduce

  1. create a new project with NextJS 9.0.0
  2. create src/ts/pages and add index.tsx
  3. run next build src/ts (note the custom project directory)

NextJS will see that you are building a TypeScript project and that you do not have a tsconfig.json and will generate one for you. Note that this file is generated in src/ts instead of where you ran next from (the project root).

Expected behavior

tsconfig.json is generated in the project root.

System information

  • OS: MacOS 10.14 (but I assume all OSes)
  • Version of Next.js: 9.0.0
@Timer
Copy link
Member

Timer commented Jul 8, 2019

Hey @tills13!

This is the expected behavior because Next.js might require specific TypeScript settings that do not agree with the rest of your application.

If you feel strongly about relocating the tsconfig.json file, you can move it to your <rootDir> and then create a stub tsconfig.json in the src/ts/ folder with the contents:

{ "extends": "../../tsconfig.json" }

@Timer Timer closed this as completed Jul 8, 2019
@tills13
Copy link
Contributor Author

tills13 commented Jul 8, 2019

That solution works for me - thanks!

@wouterds
Copy link

wouterds commented Jul 9, 2019

@Timer That's an ugly workaround (imho), I only keep actual application code in ./src. Guess I'll stick with Next.js V8 for the time being then. Edit; related: #7798 (comment), https://spectrum.chat/next-js/general/nextjs-9-typescript-and-tsconfig~a3354a2d-63be-4573-ab41-5bc05a647bd0.

@Timer
Copy link
Member

Timer commented Jul 9, 2019

@wouterds this feature is typically only used for monorepos (yes, ./src is a form of monorepo) where different tsconfig.jsons are necessary.

@tills13
Copy link
Contributor Author

tills13 commented Jul 9, 2019

While I'm ok with the above solution, it seems like tsconfig.json in particular should live where your next.config.js lives, no?

@timneutkens
Copy link
Member

For reference if we could go back in time next.config.js would not resolve up the tree and have the requirement to be inside the project directory.

@majelbstoat
Copy link

Yeah, came by to say the same thing. Having a special tsconfig.json that just extends the real one because the autogenerated file is not put at the root of the project, as it should be, is... not great.

I also don't think it's yet been mentioned that next-env.d.ts is also generated in the same place, even though I have a types directory for custom type files.

@Timer monorepos are growing ever more popular. but even if they weren't, consistency of app layout between repositories is important. it's not unusual for repos to have put their source in '/src', types in some other place, and keep configuration elsewhere. babelrc, eslint, nodemon configs etc all live at project roots. tsconfig.json is supposed to too.

Please let us specify through something in next.config.js, the locations of both tsconfig.json and next-env.d.ts. The magic autogeneration is a reasonable fallback for those who don't care.

@majelbstoat
Copy link

majelbstoat commented Jul 26, 2019

Not to mention that even if we use the workaround, the builder still automatically adds more fields to the config, including exclude: ["node_modules"] pointing to the wrong relative path.

Combined with the issue of failed imports from named exports (#7882), I can't move to Next 9, which is a real shame.

@wouterds
Copy link

wouterds commented Sep 28, 2019

I only notice now, but this has been fixed 9.0.7. I can finally use the src folder out of the box! #8451

@Albert-Gao
Copy link
Contributor

Albert-Gao commented Dec 12, 2019

I actually think this is a good feature,

I have a project which the root represents the server code

  • all the server code resides in ./server
  • nextjs sits in ./client
  • nextjs builds into './public' and server code builds into './lib'
  • express server './public' for public assets

I was worry about Next.js will pick up the tsconfig.json from the root which gonna break everything as it says so in the doc. But it ends up creating a new tsconfig.json inside ./client folder, fantastic!!!

image

Deployment is so easy for this, otherwise you need to move around the client building bundle to the folder that server code used to serve.

@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
Development

Successfully merging a pull request may close this issue.

7 participants