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

TypeScript Monorepo support? #852

Closed
AlCalzone opened this issue Feb 19, 2021 · 12 comments
Closed

TypeScript Monorepo support? #852

AlCalzone opened this issue Feb 19, 2021 · 12 comments

Comments

@AlCalzone
Copy link

I apologize in advance if this has been asked before, but I didn't find anything. I am maintaining a TypeScript monorepo managed with lerna and yarn workspaces, where I write some maintenance scripts in TypeScript.

To run these, I currently use ts-node, but that requires the referenced projects to be compiled first. Seems to be the same with esbuild and the esbuild-runner, but I guess there is a way that this should not be necessary.

Am I missing something or is this just not possible yet?

@evanw
Copy link
Owner

evanw commented Feb 19, 2021

I'm not familiar with the Lerna and Yarn ecosystems. You'll have to be specific about what isn't working with esbuild. Can you provide a code sample?

@AlCalzone
Copy link
Author

I'll see if I can create a repro repo tomorrow. This is not easily explained.

@hardfist
Copy link
Contributor

I did use esbuild in monorepo,and i donnot need to compile reference package first,all i need todo is to add an source field to package mainfield which points to source file,then configure esbuild bundle mainfieldoptions which resolve source field first

@AlCalzone
Copy link
Author

Got a link where I can see that?

@AlCalzone
Copy link
Author

While playing around with my repro repo, I got it to work when the root tsconfig.json contains paths for each package.
In my original repo that didn't work, so there must be something else going on in my repo.

Feel free to close this, although mentioning the paths setup could be something for the docs.

@camsloanftc
Copy link

I am currently trying to solve this as well and noticing this seems to be a general ts monorepo problem more than an esbuild problem. I just wanted to share this other repo that I came across that is handling typescript monorepos with a number of different use cases. Maybe we can add an example there for using esbuild.

@evanw
Copy link
Owner

evanw commented Feb 20, 2021

Are there situations where TypeScript works but esbuild doesn't? Is there something about tsconfig.json handling?

@lukeed
Copy link
Contributor

lukeed commented Feb 20, 2021

I found this on Twitter this morning – uni
I havent tried it out or anything, but maybe you'll find it useful @AlCalzone

In my projects, I just have a node script that starts a service, and then I loop through my packages/ structure, looking for & responding to any configuration files.

@Ventajou
Copy link

been using esbuild in a TS monorepo (using Yarn Workspaces) for months now, I never had an issue.

And I'm not using any paths trickery in the root tsconfig, this is what it looks like:

{
	"compilerOptions": {
		"module": "esNext",
		"target": "es2017",
		"moduleResolution": "node",
		"sourceMap": false,
		"emitDecoratorMetadata": false,
		"experimentalDecorators": true,
		"esModuleInterop": true,
		"removeComments": true,
		"noImplicitAny": true,
		"declaration": true,
		"jsx": "react",
		"allowSyntheticDefaultImports": true,
		"importHelpers": false,
		"forceConsistentCasingInFileNames": true,
		"skipLibCheck": true,
		"skipDefaultLibCheck": true,
		"incremental": true,
		"importsNotUsedAsValues": "preserve",
		"composite": true,
		"declarationMap": true,
		"typeRoots": ["./node_modules/@types", "./types"]
	}
}

And here's what the tsconfig looks like for most packages:

{
	"extends": "../../../tsconfig.json",
	"compilerOptions": {
		"baseUrl": "./",
		"paths": {
			"~/*": ["src/*"]
		}
	}
}

@AlCalzone
Copy link
Author

@hardfist Thanks - however I'm using esbuild-runner which doesn't seem to have an option to pass this to esbuild.

@evanw
Copy link
Owner

evanw commented Feb 23, 2021

I'm going to close this since it sounds like this something that is custom to specific project setups and is solved through configuration files. If this works with esbuild but not with esbuild-runner, then this sounds like an issue with esbuild-runner not with esbuild.

@evanw evanw closed this as completed Feb 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants