Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot build when composite: true in tsconfig.json #112

Closed
hassankhan opened this issue Sep 2, 2018 · 15 comments
Closed

Cannot build when composite: true in tsconfig.json #112

hassankhan opened this issue Sep 2, 2018 · 15 comments
Labels
kind: feature New feature or request kind: support Asking for support with something or a specific use case solution: duplicate This issue or pull request already exists topic: monorepo / symlinks Related to monorepos and/or symlinks (Lerna, Yarn, PNPM, Rush, etc)

Comments

@hassankhan
Copy link

hassankhan commented Sep 2, 2018

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

@ezolenko
Copy link
Owner

ezolenko commented Sep 10, 2018

A minimal repo with reproduction will help a lot. @hassankhan

@ezolenko
Copy link
Owner

This might be fixed in master now

@atifsyedali
Copy link

atifsyedali commented Oct 9, 2019

This happens when using composite: true AND using paths in tsconfig with glob pattern matching.

@TomzBench
Copy link

TomzBench commented Mar 5, 2021

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

@Domino9697

This comment was marked as duplicate.

@Domino9697
Copy link

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

@fatihaziz
Copy link

+1 I got the same issue,
removing "composite": true solving the problem but, it might rise another problem for others

@agilgur5 agilgur5 added the topic: monorepo / symlinks Related to monorepos and/or symlinks (Lerna, Yarn, PNPM, Rush, etc) label May 8, 2022
@agilgur5
Copy link
Collaborator

agilgur5 commented May 8, 2022

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

@agilgur5 agilgur5 changed the title Cannot build when "composite" is true in tsconfig.json Cannot build when composite: true in tsconfig.json May 22, 2022
@agilgur5 agilgur5 added the problem: stale Issue has not been responded to in some time label Jun 8, 2022
@jsgoupil
Copy link

jsgoupil commented Sep 28, 2023

OMG, so much work to get this to work. Going through the thread here shows that it's not working out of the box. Removing the "paths" starts working indeed.

You can make it pass by doing this:

typescript({
  tsconfig: "tsconfig.lib.json",

  // https://github.com/ezolenko/rollup-plugin-typescript2/issues/112
  tsconfigOverride: {
    compilerOptions: { paths: {} },
  },
}),

@agilgur5
Copy link
Collaborator

Yes, as I mentioned above, paths are not "true" aliases by the TS compiler. That's not rpt2's behavior, that's TS behavior. Per above, see #201 for more details, links to upstream TS issues, and workarounds for that limitation, such as custom transformers.

Sounds like references works without paths though, so this feature is working. Thanks for confirming that!
Closing as duplicate of #201 and #139.

@agilgur5 agilgur5 added solution: duplicate This issue or pull request already exists kind: feature New feature or request kind: support Asking for support with something or a specific use case and removed problem: needs more info This issue needs more information in order to handle it problem: stale Issue has not been responded to in some time labels Sep 28, 2023
@jsgoupil
Copy link

@agilgur5 sorry that is a lot of lingos that I'm not familiar.
Do you have a better fix than my workaround I just posted?
Should this work out of the box?

@agilgur5
Copy link
Collaborator

agilgur5 commented Sep 29, 2023

paths do not and cannot work out of the box, as TS did not design them to be aliases (they are the inverse, basically).

references do work, as you confirmed.

If you want to use paths, #201 has several workarounds, the main one of which custom transformers (@rollup/plugin-alias works too I believe -- that issue has it all).

@jsgoupil
Copy link

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.

@agilgur5
Copy link
Collaborator

Hmmmm that's a good suggestion as paths are unfortunately very commonly misunderstood, but I'm not sure if we can know for sure that it's not being used correctly 💭 (e.g. if you're using it together with plugin-alias)

We could have a manual flag to turn off that warning I suppose, for when someone knows they're using it correctly. @jsgoupil could you file a separate issue for that so we can track it properly?

@jsgoupil
Copy link

I'm not super proficient in this space, I think it would be better if you create it. I literally inherited a project and used rollup for the first time today. I'm still learning around this.

If I may suggest, maybe a well known variable, when you detect a paths in the configuration you display the warning that's silenceable either by the user, or a plug-in could come in and silence that warning as well?

The paths + references seems to be the way to do monorepos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: feature New feature or request kind: support Asking for support with something or a specific use case solution: duplicate This issue or pull request already exists topic: monorepo / symlinks Related to monorepos and/or symlinks (Lerna, Yarn, PNPM, Rush, etc)
Projects
None yet
Development

No branches or pull requests

8 participants