rollup-plugin-typescript2: Cannot build when `composite: true` in tsconfig.json

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

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 12
  • Comments: 15 (2 by maintainers)

Most upvoted comments

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

@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.

Thanks for the info. May propose to get a warning about the usage of paths, because right now it doesn’t point to that direction at all, but only saying it’s having trouble with the rootDir.

So it seems like per the repro above (thank you!), references seems to work fine without paths, as far as I can tell. This plugin does have some specific code around references (c.f. #139 etc)

Since paths are not treated as “true” aliases by the underlying TS API itself, they cause a lot of confusion in the ecosystem and community (c.f. #201 ), so removing them can often solve a variety of issues. Per that issue, could also try a custom transformer to get paths to work differently from the TS API; that may or may not work to get references and paths working together.

If references indeed work without paths (I have not tested thoroughly and don’t typically use references myself), then this issue can be closed as duplicative of the two issues I linked above

This might be fixed in master now