Replies: 13 comments 23 replies
-
Great work diving into this all! My project structure is a bit different so wanted to share. You've dug into this a ton more than I have so I don't know how helpful I can be aside from saying that I would love to see Next natively support this (without next-transpile-modules). My project:
I deploy each Next app separately (will be over a dozen for now), packages are published to npm separately, and each Next tsconfig is extended from one of the packages (as a util). I don't use baseUrl because my packages are published and imported via the package name without aliases. Because of how yarn workspaces resolves packages, I decided to not use /dist folders on the package builds and added a pre-publish script to update my package.json main. On dev, I can resolve, but not transpile so I use next-transpile-modules. Curious how your proposal would work for my scenario. I'm open to adjusting my project structure if there's a better way, but as far as I remember baseUrl didn't work for me. |
Beta Was this translation helpful? Give feedback.
-
Everything is OK. Dev is ideal right now because yarn workspaces symlinks to the monorepo packages. Next dev is pulling in source files to the apps so the entire monorepo is hot. I did this so I can do testing with all package components and tweak packages without running a separate build/watch task. Publishing is done via Actions and orchestrated before deploys.
My only concern right now is my use of next-transpile-modules in all of my next apps.
Do you have any links to projects that use a baseUrl structure similar to what you propose? I checked many of the links above but there wasn’t anything very complex like what I have.
|
Beta Was this translation helpful? Give feedback.
-
Ah ok no worries, thanks. I will give your PR a try this week and do some testing with my configuration.
|
Beta Was this translation helpful? Give feedback.
-
What's the status of this? |
Beta Was this translation helpful? Give feedback.
-
@jeantil I'm experimenting with the baseUrl approach and produced a working example repo. https://github.com/belgattitude/next-transpile-ts-workspace I would like to propose an official example for next Do you mind to have a look ? |
Beta Was this translation helpful? Give feedback.
-
I'm on vacation at the moment, I'll have a look next week when I'm back. If
you look at the referenced PRs there is an integration test which
demonstrates a monorepo with both baseUrl ( first PR merged) and baseUrl +
automatic transpilation (second PR not merged yet) of code below baseUrl
Regards
Le mar. 18 août 2020 à 08:55, Sébastien Vanvelthem <notifications@github.com>
a écrit :
… @jeantil <https://github.com/jeantil> I'm experimenting with the baseUrl
approach and produced a working example repo.
https://github.com/belgattitude/next-transpile-ts-workspace
I would like to propose an official example for next
Do you mind to have a look ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#15327 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAFTQZC36R3BFPWWJXW7DDSBIQWBANCNFSM4PCK3NPA>
.
|
Beta Was this translation helpful? Give feedback.
-
however I'm seeing some issues when using with Vercel's new monorepo
support:
- Extending a tsconfig from the project root will fail on Vercel due
to not being able to resolve the config in the cwd above the project folder.
- Tsconfig paths set in the nested Next project's tsconfig do not work
when deploying, I assume because of similar reason.
@jeantil <https://github.com/jeantil>, did you run into this?
I'm not sure, for me it didn't work locally either, ence the 2nd PR.
Without specific configuration, next transpiles typescript code using
babel, but only if the code is in the next.config.js directory or in a
subdirectory of that.
When using typescript paths in a monorepo you will usually extend a
tsconfig which is in a parent directory of the directory which contains
next.config.js in which case baseUrl will most likely also resolve to a
parent directory.
When webpack resolves the files for your imports it will correctly resolve
the path to the typescript files but the babel transpilation is restricted
to paths that are below next.config.js and webpack fails to load the
typescript files since they are not transpiler.
If you merged the pr it will work locally but to get it to work on vercel
you will have to publish your own version of next since the second part of
the fix is not in official builds
—
… You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#15327 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAFTQ4FGRVRCQADT7YG4BDSBKNDRANCNFSM4PCK3NPA>
.
|
Beta Was this translation helpful? Give feedback.
-
Is the nextjs team aware of this thread? |
Beta Was this translation helpful? Give feedback.
-
@jeantil I'm really interested in this RFC, haven't really participated yet cause I need to experiment first. I researched a bit pros and cons:
I'll need to test it out more, but do you think it would be possible to include css/scss support as well ? My test repo is here: https://github.com/belgattitude/vercel-monorepo-test |
Beta Was this translation helpful? Give feedback.
-
@timneutkens @jeantil |
Beta Was this translation helpful? Give feedback.
This comment was marked as spam.
This comment was marked as spam.
-
Is there any progress with this? With Vercel acquiring turborepo, seems extremely necessary. |
Beta Was this translation helpful? Give feedback.
-
@amlcodes Is the new experimental flag in netxtjs 10.2+ does solve your issue ?
Just add in your next.config.js const nextConfig = {
experimental: {
externalDir: true,
},
};
export default nextConfig; Working example here: https://github.com/belgattitude/nextjs-monorepo-example |
Beta Was this translation helpful? Give feedback.
-
Related PR
baseUrl
#15569 (pending - automatically enables transpilation for modules which are resolved through path aliases/baseUrl)Related issues:
RFC
Initially PR improves baseUrl resolution in typescript monorepos #13542 was written to solve Failure to resolve modules from yarn workspaces when module has rootDir/outDir #13197 and make it easier to build next projects which are a module within a monorepo. There were two issues that needed to be fixed: properly resolving modules internal to the monorepo and transpiling the files in the internally resolved modules since such modules are built alongside the next app and are not necessarily destined to be published in a normal manner.
Solving the module resolution depended in resolving the full typescript config and using that to build the proper aliases and was fixed by improves baseUrl resolution in typescript monorepos #13542.
Transpiling internal modules requires changing the babel-loader configuration to include paths which are outside of the directory which depends on next.
Current situation
Without improves baseUrl resolution in typescript monorepos #13542 files in monorepo modules a next project depends on, would not be resolved correctly, naively adding a nextjs app in a monorepo results in a cryptic resolution failure even though the documentation states that path aliases are supported and automatically derived from tsconfig
With improves baseUrl resolution in typescript monorepos #13542 the modules are correctly resolved but they are not transpiled, so in a project with the following structure
Typescript or javascript files in
packages/www
will automatically be transpiled but files inpackages/lib
won't which I found surprising.Proposal
Automatically including the configured
baseUrl
in the transpilation root ofnext-babel-loader
would completely remove the need for a customnext.config.js
and automatically transpile files resolved within the same monorepo through path alises.Beta Was this translation helpful? Give feedback.
All reactions