Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 235
Nicolas SEPTIER Avatar asked Sep 10 '25 23:09

Nicolas SEPTIER


1 Answers

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

like image 59
Gabriel Avatar answered Sep 12 '25 13:09

Gabriel