I'm trying to setup a monorepo project using typescript and yarn workspaces.
The project's structure looks like this:
/example
/packages
/lib1
Example is an app that used the packages, for development purposes.
When I use yarn tsc --build --force
I get the following error:
example/tsconfig.json:6:18 - error TS6310: Referenced project '/packages/intro' may not disable emit.
Here's example's tsconfig.json:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "./lib"
},
"references": [{ "path": "../packages/intro" }]
}
And the one at the project's root:
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "React Native",
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"composite": true,
"declaration": true,
"esModuleInterop": true,
"isolatedModules": true,
"jsx": "react-native",
"lib": ["es2017"],
"module": "commonjs",
"moduleResolution": "node",
"noEmit": true,
"paths": {
"my-project/*": ["./packages/*/src"]
},
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "esnext"
},
"exclude": [
"packages/*/lib",
"node_modules",
"babel.config.js",
"metro.config.js",
"jest.config.js"
],
"references": [{ "path": "./example" }, { "path": "./packages/lib1" }]
}
And the lib1's tsconfig.json:
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./lib"
}
}
As you can see I do have noEmit
set to true
so I don't understand what the error is about. I've tried setting the value directly in each tsconfig files but that didn't do anything as expected.
You can use either noEmit or emitDeclarationOnly fields individually without having to specify the other, to fix your issue - try replacing noEmit with emitDeclarationOnly, e.g:
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "React Native",
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"composite": true,
"declaration": true,
"esModuleInterop": true,
"isolatedModules": true,
"jsx": "react-native",
"lib": ["es2017"],
"module": "commonjs",
"moduleResolution": "node",
"emitDeclarationOnly": true, // use this field instead of "noEmit"
"paths": {
"my-project/*": ["./packages/*/src"]
},
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "esnext"
},
"exclude": [
"packages/*/lib",
"node_modules",
"babel.config.js",
"metro.config.js",
"jest.config.js"
],
"references": [{ "path": "./example" }, { "path": "./packages/lib1" }]
}
sources:
https://www.typescriptlang.org/tsconfig#noEmit
https://www.typescriptlang.org/tsconfig#emitDeclarationOnly
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With