'Typescript/yarn workspaces - Referenced project may not disable emit

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.



Solution 1:[1]

Setting noEmit to true disables emitting, which is what the error is saying. You need to set noEmit to false to enable emitting.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mal Curtis