question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot build when `composite: true` in tsconfig.json

See original GitHub issue

What happens and why it is wrong

This bug is occurring in a monorepo project managed with Yarn Workspaces. I’ve recently upgraded it to TypeScript 3 and was looking to take advantage of Project References. To do this, I set composite: true under compilerOptions in tsconfig.json for each subpackage. If I set it to false, then everything works fine.

Interestingly, builds using tsc work fine, only when using Rollup does this issue occur.

Environment

  • macOS: 10.13.6
  • node: 8.11.1
  • typescript: 3.0.1

Versions

  • typescript: 3.0.1
  • rollup: 0.65.0
  • rollup-plugin-typescript2: 0.17.0

rollup.config.js

I use a script to generate a Rollup configuration, the results of which are below:

Generated Rollup Config
{
  "external": [],
  "plugins": [
    {
      "name": "json"
    },
    {
      "name": "rpt2"
    },
    {
      "name": "commonjs"
    },
    {
      "name": "node-resolve"
    },
    {
      "name": "sourcemaps"
    }
  ],
  "watch": {
    "include": "src/**"
  },
  "input": "src/index.ts",
  "output": [
    {
      "file": "dist/lambda.umd.js",
      "name": "lambda",
      "format": "umd",
      "sourcemap": true
    },
    {
      "file": "dist/lambda.es5.js",
      "format": "es",
      "sourcemap": true
    }
  ]
}

tsconfig.json

Root
{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "baseUrl": "./packages",
    "composite": true,
    "declaration": true,
    "emitDecoratorMetadata": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "forceConsistentCasingInFileNames": true,
    "importHelpers": true,
    "lib": [
      "es2015",
      "es2016",
      "es2017",
      "esnext.asynciterable"
    ],
    "module":"commonjs",
    "moduleResolution": "node",
    "paths": {
      "@serverlize/*": ["./*/src"]
    },
    "sourceMap": true,
    "strict": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types",
      "../../node_modules/@types"
    ]
  },
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ]
}
Project
{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "declarationDir": "dist/types",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "outDir": "dist/lib"
  },
  "include": [
    "src"
  ],
  "references": [
    { "path": "../cdk" },
    { "path": "../support" }
  ]
}

package.json

plugin output with verbosity 3

Output
$ rollup -c

src/index.ts → dist/lambda.umd.js, dist/lambda.es5.js...
rpt2: typescript version: 3.0.1
rpt2: tslib version: 1.9.3
rpt2: rollup-plugin-typescript2 version: 0.17.0
rpt2: plugin options:
{
    "useTsconfigDeclarationDir": true,
    "verbosity": 3,
    "check": true,
    "clean": false,
    "cacheRoot": "/[PROJECT_ROOT]/packages/lambda/.rpt2_cache",
    "include": [
        "*.ts+(|x)",
        "**/*.ts+(|x)"
    ],
    "exclude": [
        "*.d.ts",
        "**/*.d.ts"
    ],
    "abortOnError": true,
    "rollupCommonJSResolveHack": false,
    "typescript": "version 3.0.1",
    "tsconfigOverride": {},
    "transformers": [],
    "tsconfigDefaults": {},
    "objectHashIgnoreUnknownHack": false
}
rpt2: rollup config:
{
    "experimentalCacheExpiry": 10,
    "external": [
        "",
        ""
    ],
    "inlineDynamicImports": false,
    "input": "src/index.ts",
    "chunkGroupingSize": 5000,
    "perf": false,
    "plugins": [
        {
            "name": "json"
        },
        {
            "name": "rpt2"
        },
        {
            "name": "commonjs"
        },
        {
            "name": "node-resolve"
        },
        {
            "name": "sourcemaps"
        }
    ],
    "watch": {
        "include": "src/**"
    },
    "entry": "src/index.ts"
}
rpt2: built-in options overrides: {
    "noEmitHelpers": false,
    "importHelpers": true,
    "noResolve": false,
    "noEmit": false,
    "inlineSourceMap": false,
    "outDir": "/[PROJECT_ROOT]/packages/lambda/.rpt2_cache/placeholder",
    "moduleResolution": 2,
    "declarationDir": null,
    "sourceRoot": null
}
rpt2: parsed tsconfig: {
    "options": {
        "allowSyntheticDefaultImports": true,
        "baseUrl": "/[PROJECT_ROOT]/packages",
        "composite": true,
        "declaration": true,
        "emitDecoratorMetadata": true,
        "esModuleInterop": true,
        "experimentalDecorators": true,
        "forceConsistentCasingInFileNames": true,
        "importHelpers": true,
        "lib": [
            "lib.es2015.d.ts",
            "lib.es2016.d.ts",
            "lib.es2017.d.ts",
            "lib.esnext.asynciterable.d.ts"
        ],
        "module": 5,
        "moduleResolution": 2,
        "paths": {
            "@serverlize/*": [
                "./*/src"
            ]
        },
        "sourceMap": true,
        "strict": true,
        "target": 2,
        "typeRoots": [
            "/[PROJECT_ROOT]/node_modules/@types",
            "/Users/hassankhan/Projects/endemolshine/open-source/node_modules/@types"
        ],
        "declarationDir": null,
        "outDir": "/[PROJECT_ROOT]/packages/lambda/.rpt2_cache/placeholder",
        "configFilePath": "/[PROJECT_ROOT]/packages/lambda/tsconfig.json",
        "noEmitHelpers": false,
        "noResolve": false,
        "noEmit": false,
        "inlineSourceMap": false,
        "sourceRoot": null
    },
    "fileNames": [
        "/[PROJECT_ROOT]/packages/lambda/src/enhance.ts",
        "/[PROJECT_ROOT]/packages/lambda/src/index.ts",
        "/[PROJECT_ROOT]/packages/lambda/src/types.ts",
        "/[PROJECT_ROOT]/packages/lambda/src/Annotations/Function.ts"
    ],
    "projectReferences": [
        {
            "path": "/[PROJECT_ROOT]/packages/cdk",
            "originalPath": "../cdk"
        },
        {
            "path": "/[PROJECT_ROOT]/packages/support",
            "originalPath": "../support"
        }
    ],
    "typeAcquisition": {
        "enable": false,
        "include": [],
        "exclude": []
    },
    "raw": {
        "compilerOptions": {
            "module": "ES2015",
            "declarationDir": "dist/types",
            "emitDecoratorMetadata": true,
            "experimentalDecorators": true,
            "outDir": "dist/lib"
        },
        "extends": "../../tsconfig.json",
        "include": [
            "src"
        ],
        "references": [
            {
                "path": "../cdk"
            },
            {
                "path": "../support"
            }
        ],
        "compileOnSave": false,
        "exclude": [
            "../../node_modules",
            "../../**/*.spec.ts"
        ]
    },
    "errors": [],
    "wildcardDirectories": {
        "/[PROJECT_ROOT]/packages/lambda/src": 1
    },
    "compileOnSave": false,
    "configFileSpecs": {
        "includeSpecs": [
            "src"
        ],
        "excludeSpecs": [
            "../../node_modules",
            "../../**/*.spec.ts"
        ],
        "validatedIncludeSpecs": [
            "src"
        ],
        "validatedExcludeSpecs": [
            "../../node_modules",
            "../../**/*.spec.ts"
        ],
        "wildcardDirectories": {
            "/[PROJECT_ROOT]/packages/lambda/src": 1
        }
    }
}
rpt2: included:
'[
    "*.ts+(|x)",
    "**/*.ts+(|x)"
]'
rpt2: excluded:
'[
    "*.d.ts",
    "**/*.d.ts"
]'
rpt2: options error TS6059 File '/[PROJECT_ROOT]/packages/cdk/src/index.ts' is not under 'rootDir' '/[PROJECT_ROOT]/packages/lambda'. 'rootDir' is expected to contain all source files.
rpt2: options error TS6307 File '/[PROJECT_ROOT]/packages/cdk/src/index.ts' is not in project file list. Projects must list all files or use an 'include' pattern.
rpt2: Ambient types:
rpt2:     /[PROJECT_ROOT]/node_modules/@types/aws-lambda/index.d.ts
rpt2:     /[PROJECT_ROOT]/node_modules/@types/cosmiconfig/index.d.ts
rpt2:     /[PROJECT_ROOT]/node_modules/@types/estree/index.d.ts
rpt2:     /[PROJECT_ROOT]/node_modules/@types/events/index.d.ts
rpt2:     /[PROJECT_ROOT]/node_modules/@types/execa/index.d.ts
rpt2:     /[PROJECT_ROOT]/node_modules/@types/fs-extra/index.d.ts
rpt2:     /[PROJECT_ROOT]/node_modules/@types/glob/index.d.ts
rpt2:     /[PROJECT_ROOT]/node_modules/@types/handlebars/index.d.ts
rpt2:     /[PROJECT_ROOT]/node_modules/@types/highlight.js/index.d.ts
rpt2:     /[PROJECT_ROOT]/node_modules/@types/jest/index.d.ts
rpt2:     /[PROJECT_ROOT]/node_modules/@types/lodash/index.d.ts
rpt2:     /[PROJECT_ROOT]/node_modules/@types/lodash.find/index.d.ts
rpt2:     /[PROJECT_ROOT]/node_modules/@types/lodash.get/index.d.ts
rpt2:     /[PROJECT_ROOT]/node_modules/@types/lodash.has/index.d.ts
rpt2:     /[PROJECT_ROOT]/node_modules/@types/lodash.isarray/index.d.ts
rpt2:     /[PROJECT_ROOT]/node_modules/@types/lodash.pick/index.d.ts
rpt2:     /[PROJECT_ROOT]/node_modules/@types/marked/index.d.ts
rpt2:     /[PROJECT_ROOT]/node_modules/@types/minimatch/index.d.ts
rpt2:     /[PROJECT_ROOT]/node_modules/@types/node/index.d.ts
rpt2:     /[PROJECT_ROOT]/node_modules/@types/shelljs/index.d.ts
rpt2: transpiling '/[PROJECT_ROOT]/packages/lambda/src/index.ts'
rpt2:     cache: '/[PROJECT_ROOT]/packages/lambda/.rpt2_cache/rpt2_b33a1f7fab3e88a4c8f2f4b6aebb7d3309529ba6/code/cache/2f121cf4034321b46ef658bd341dd2c4f6c96d1f'
rpt2:     cache hit
rpt2:     cache: '/[PROJECT_ROOT]/packages/lambda/.rpt2_cache/rpt2_b33a1f7fab3e88a4c8f2f4b6aebb7d3309529ba6/syntacticDiagnostics/cache/2f121cf4034321b46ef658bd341dd2c4f6c96d1f'
rpt2:     cache hit
rpt2:     cache: '/[PROJECT_ROOT]/packages/lambda/.rpt2_cache/rpt2_b33a1f7fab3e88a4c8f2f4b6aebb7d3309529ba6/semanticDiagnostics/cache/2f121cf4034321b46ef658bd341dd2c4f6c96d1f'
rpt2:     cache hit
rpt2: generated declarations for '/[PROJECT_ROOT]/packages/lambda/src/index.ts'
rpt2: dependency '/[PROJECT_ROOT]/packages/lambda/src/enhance.ts'
rpt2:     imported by '/[PROJECT_ROOT]/packages/lambda/src/index.ts'
rpt2: resolving './enhance'
rpt2:     to '/[PROJECT_ROOT]/packages/lambda/src/enhance.ts'
rpt2: transpiling '/[PROJECT_ROOT]/packages/lambda/src/enhance.ts'
rpt2:     cache: '/[PROJECT_ROOT]/packages/lambda/.rpt2_cache/rpt2_b33a1f7fab3e88a4c8f2f4b6aebb7d3309529ba6/code/cache/d250d6bf85931e257b7af5ef161fc4f4384a5df9'
rpt2:     cache hit
rpt2:     cache: '/[PROJECT_ROOT]/packages/lambda/.rpt2_cache/rpt2_b33a1f7fab3e88a4c8f2f4b6aebb7d3309529ba6/syntacticDiagnostics/cache/d250d6bf85931e257b7af5ef161fc4f4384a5df9'
rpt2:     cache hit
rpt2:     cache: '/[PROJECT_ROOT]/packages/lambda/.rpt2_cache/rpt2_b33a1f7fab3e88a4c8f2f4b6aebb7d3309529ba6/semanticDiagnostics/cache/d250d6bf85931e257b7af5ef161fc4f4384a5df9'
rpt2:     cache hit
rpt2: generated declarations for '/[PROJECT_ROOT]/packages/lambda/src/enhance.ts'
rpt2: resolving './isPromise'
rpt2:     to '/[PROJECT_ROOT]/node_modules/@middy/core/isPromise.js'
rpt2: resolving 'once'
rpt2:     to '/[PROJECT_ROOT]/node_modules/once/once.js'
rpt2: resolving './isPromise'
rpt2:     to '/[PROJECT_ROOT]/node_modules/@middy/core/isPromise.js'
rpt2: resolving 'once'
rpt2:     to '/[PROJECT_ROOT]/node_modules/once/once.js'
rpt2: resolving 'wrappy'
rpt2:     to '/[PROJECT_ROOT]/node_modules/wrappy/wrappy.js'
rpt2: resolving 'wrappy'
rpt2:     to '/[PROJECT_ROOT]/node_modules/wrappy/wrappy.js'
rpt2: resolving '/[PROJECT_ROOT]/node_modules/@middy/core/isPromise.js'
rpt2:     to '/[PROJECT_ROOT]/node_modules/@middy/core/isPromise.js'
rpt2: resolving '/[PROJECT_ROOT]/node_modules/once/once.js'
rpt2:     to '/[PROJECT_ROOT]/node_modules/once/once.js'
rpt2: resolving '/[PROJECT_ROOT]/node_modules/wrappy/wrappy.js'
rpt2:     to '/[PROJECT_ROOT]/node_modules/wrappy/wrappy.js'
rpt2: generating target 1
rpt2: rolling caches
rpt2: generating target 2
rpt2: rolling caches
rpt2: generating missed declarations for '/[PROJECT_ROOT]/packages/lambda/src/types.ts'
rpt2: generating missed declarations for '/[PROJECT_ROOT]/packages/lambda/src/Annotations/Function.ts'
rpt2: writing declarations for '/[PROJECT_ROOT]/packages/lambda/src/index.ts' to '/[PROJECT_ROOT]/packages/lambda/.rpt2_cache/placeholder/src/index.d.ts'
rpt2: writing declarations for '/[PROJECT_ROOT]/packages/lambda/src/enhance.ts' to '/[PROJECT_ROOT]/packages/lambda/.rpt2_cache/placeholder/src/enhance.d.ts'
rpt2: writing declarations for '/[PROJECT_ROOT]/packages/lambda/src/types.ts' to '/[PROJECT_ROOT]/packages/lambda/.rpt2_cache/placeholder/src/types.d.ts'
rpt2: writing declarations for '/[PROJECT_ROOT]/packages/lambda/src/Annotations/Function.ts' to '/[PROJECT_ROOT]/packages/lambda/.rpt2_cache/placeholder/src/Annotations/Function.d.ts'
rpt2: writing declarations for '/[PROJECT_ROOT]/packages/lambda/src/index.ts' to '/[PROJECT_ROOT]/packages/lambda/.rpt2_cache/placeholder/src/index.d.ts'
rpt2: writing declarations for '/[PROJECT_ROOT]/packages/lambda/src/enhance.ts' to '/[PROJECT_ROOT]/packages/lambda/.rpt2_cache/placeholder/src/enhance.d.ts'
rpt2: writing declarations for '/[PROJECT_ROOT]/packages/lambda/src/types.ts' to '/[PROJECT_ROOT]/packages/lambda/.rpt2_cache/placeholder/src/types.d.ts'
rpt2: writing declarations for '/[PROJECT_ROOT]/packages/lambda/src/Annotations/Function.ts' to '/[PROJECT_ROOT]/packages/lambda/.rpt2_cache/placeholder/src/Annotations/Function.d.ts'
created dist/lambda.umd.js, dist/lambda.es5.js in 1.4s

Similar issues

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:10
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
TomzBenchcommented, Jun 21, 2022

I gave up trying to figure this out. I have a monorepo with a root tsconfig that has paths configured for each sub project, so I can import the project with out a bunch of "../../../". Then, each subproject extends the root tsconfig and has its "references": [] populated to the subprojects they depend on. Running tsc on its own works as expected. When running through Rollup using the same tsconfig, I receive a typescript error that is the same error as if I forgot to add a project to the "references" property.

For example, if I delete a dependency from my references, then I get the error "../../../file.ts is not inside root dir". This error always reminds me to add the project to the "references" of my tsconfig. However, when I run through Rollup, it is as if ALL of references are not passed to the TS compiler.

The typescript API requires you to pass the references explicitly. I’m guessing that is the issue here

2reactions
Domino9697commented, Apr 22, 2021

@TomzBench @ezolenko I made a simple repo to reproduce the issue here: https://github.com/Domino9697/rollup-ts-issue-repro

@atifsyedali and @TomzBench summed it up pretty much. Whenever we want to use references along with paths in the tsconfig files, the plugin outputs an error as if the reference was not set anymore.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular SSR: Build Error TS6306: Referenced project must ...
Step 1. Add composite: true in tsconfig.app.json inside compilerOptions like below /* To learn more about this file see: ...
Read more >
TSConfig Reference - Docs on every TSConfig option
If composite is set, the default is instead the directory containing the tsconfig.json file. When TypeScript compiles files, it keeps the same directory ......
Read more >
A guide through The Wild Wild West of setting up a mono repo ...
We have to modify the tsconfig.json of our packages. By setting “composite” to true, we let TypeScript know we want to use project...
Read more >
Exploring advanced compiler options in TypeScript
The TypeScript compiler can reference a tsconfig.json file in another ... compiler option set to true , the compiler will generate an error:...
Read more >
Incremental (composite) Typescript does not work for test files
Also production code works fine with IntelliJ. The problem is with test files that should use tsconfig.test.json These files show errors and can't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found