Skip to content

Project with project references and outFile fails to build #34846

Closed

Description

@ecl1ps

TypeScript Version:

3.8.0-dev.20191031

Search Terms:

"project references" paths outfile "has not been built from source file"

Code

https://github.com/ecl1ps/project-references-demo/tree/amd-outfile

Project structure

/src
    /animals
        tsconfig.json
        dog.ts
        index.ts
    /zoo
        tsconfig.json
        zoo.ts
tsconfig.json
tsconfig-base.json

tsconfig-base.json

{
    "compilerOptions": {
        "declaration": true,
        "declarationMap": true,
        "module": "amd",
        "composite": true,
        "rootDir": "./src",
        "baseUrl": "./src",
        "moduleResolution": "node"
    }
}

src/zoo/tsconfig.json

{
  "extends": "../../tsconfig-base.json",
  "compilerOptions": {
    "outFile": "../../lib/zoo/zoo.bundle.js",
    "paths": {
      "@animals": ["./animals"],
      "@animals/*": ["./animals/*"],
    }
  },
  "references": [{ "path": "../animals" }]
}
import { createDog } from '../animals';  // fails

import { Dog as Dog1 } from 'animals/dog';  // ok
import { Dog as Dog2 } from 'animals';  // fails

import { Dog as Dog3 } from '@animals/dog';  // fails
import { Dog as Dog4 } from '@animals';  // fails

export function createZoo(): Array<Dog1 | Dog2 | Dog3 | Dog4> {
    return [ createDog() ];
}

Expected behavior:

Project will be built without errors.

Actual behavior:

Project build (tsc -b) fails with four errors TS6305: Output file '[...]/lib/animals/animals.bundle.d.ts' has not been built from source file '[...]/src/animals/dog.ts'.. One for each import marked in code above as // fails.

Module resolution succeedes for every import. Log below.

This problem occurs only when using outFile compiler directive. Compilation using outDir finishes without problem. See repro repository with the exactly same project just with outDir settings: https://github.com/ecl1ps/project-references-demo/tree/amd-outdir branch amd-outdir.

Repro Repository Link:

https://github.com/ecl1ps/project-references-demo/tree/amd-outfile branch amd-outfile

Related Issues:

Module Resolution Log

Log ``` Building project '/src/zoo/tsconfig.json'...

Module 'animals/animal' was resolved as locally declared ambient module in file '/lib/animals/animals.bundle.d.ts'.
Module 'animals/animal' was resolved as locally declared ambient module in file '/lib/animals/animals.bundle.d.ts'.
Module 'animals/dog' was resolved as locally declared ambient module in file '/lib/animals/animals.bundle.d.ts'.

======== Resolving module '../animals' from '/src/zoo/zoo.ts'. ========
Explicitly specified module resolution kind: 'NodeJs'.
Loading module as file / folder, candidate module location '/src/animals', target file type 'TypeScript'.
File '/src/animals.ts' does not exist.
File '/src/animals.tsx' does not exist.
File '/src/animals.d.ts' does not exist.
File '/src/animals/package.json' does not exist.
File '/src/animals/index.ts' exist - use it as a name resolution result.
======== Module name '../animals' was successfully resolved to '/src/animals/index.ts'. ========

======== Resolving module 'animals/dog' from '/src/zoo/zoo.ts'. ========
Explicitly specified module resolution kind: 'NodeJs'.
'baseUrl' option is set to '/src', using this value to resolve non-relative module name 'animals/dog'.
'paths' option is specified, looking for a pattern to match module name 'animals/dog'.
'baseUrl' option is set to '/src', using this value to resolve non-relative module name 'animals/dog'.
Resolving module name 'animals/dog' relative to base url '/src' - '/src/animals/dog'.
Loading module as file / folder, candidate module location '/src/animals/dog', target file type 'TypeScript'.
File '/src/animals/dog.ts' exist - use it as a name resolution result.
======== Module name 'animals/dog' was successfully resolved to '/src/animals/dog.ts'. ========

======== Resolving module 'animals' from '/src/zoo/zoo.ts'. ========
Explicitly specified module resolution kind: 'NodeJs'.
'baseUrl' option is set to '/src', using this value to resolve non-relative module name 'animals'.
'paths' option is specified, looking for a pattern to match module name 'animals'.
'baseUrl' option is set to '/src', using this value to resolve non-relative module name 'animals'.
Resolving module name 'animals' relative to base url '/src' - '/src/animals'.
Loading module as file / folder, candidate module location '/src/animals', target file type 'TypeScript'.
File '/src/animals.ts' does not exist.
File '/src/animals.tsx' does not exist.
File '/src/animals.d.ts' does not exist.
File '/src/animals/package.json' does not exist.
File '/src/animals/index.ts' exist - use it as a name resolution result.
======== Module name 'animals' was successfully resolved to '/src/animals/index.ts'. ========

======== Resolving module '@animals/dog' from '/src/zoo/zoo.ts'. ========
Explicitly specified module resolution kind: 'NodeJs'.
'baseUrl' option is set to '/src', using this value to resolve non-relative module name '@animals/dog'.
'paths' option is specified, looking for a pattern to match module name '@animals/dog'.
Module name '@animals/dog', matched pattern '@animals/'.
Trying substitution './animals/
', candidate module location: './animals/dog'.
Loading module as file / folder, candidate module location '/src/animals/dog', target file type 'TypeScript'.
File '/src/animals/dog.ts' exist - use it as a name resolution result.
======== Module name '@animals/dog' was successfully resolved to '/src/animals/dog.ts'. ========

======== Resolving module 'Animals' from '/src/zoo/zoo.ts'. ========
Explicitly specified module resolution kind: 'NodeJs'.
'baseUrl' option is set to '/src', using this value to resolve non-relative module name 'Animals'.
'paths' option is specified, looking for a pattern to match module name 'Animals'.
Module name 'Animals', matched pattern 'Animals'.
Trying substitution './animals', candidate module location: './animals'.
Loading module as file / folder, candidate module location '/src/animals', target file type 'TypeScript'.
File '/src/animals.ts' does not exist.
File '/src/animals.tsx' does not exist.
File '/src/animals.d.ts' does not exist.
File '/src/animals/package.json' does not exist.
File '/src/animals/index.ts' exist - use it as a name resolution result.
======== Module name 'Animals' was successfully resolved to '/src/animals/index.ts'. ========

</details>

Activity

  1. sheetalkamat commented on Oct 31, 2019

    @sheetalkamat
    Member

    I think it is correct to report error on modules "../animals" or "@animals/dog" since these modules don't exist in the program. (as program includes the bundled d.ts it only contains module definitions for `animals/animal" and such... The error message however is misleading and can do with better error..
    Will let Ryan Cavanaugh (@RyanCavanaugh) confirm if erroring is desired behavior here..

  2. ecl1ps commented on Dec 6, 2019

    @ecl1ps
    Author

    Hello, have you had time to look into it? It would be great if we could get an info whether this will get resolved or what is the recommended approach to this topic. This is blocking us from completing out transition to Project References.

    I'll try to describe our use case more closely.

    Medium sized project, collection of libraries used by us and also by third parties. Previously one mostly monolithic codebase. Now being separated into standalone modules/libraries using Project References.

    Our expectations is that build should produce single file for each project. Each such file (library if you wish) should reexport its public members (see animals/index.ts) so they are accessible for importing from library through it's main module name.

    So consument could use import { Dog } from 'animals'; and not care about library's internals.

    I haven't found a way how to do this as only "full module path" imports (import { Dog } from 'animals/dog';) are working in this configuration.

    This is working well with outDir settings. It is supposed to NOT work with outFile? If so, what is the officially recommended approach?

    Thank you wery much for your time.

  3. ecl1ps commented on Jan 21, 2020

    @ecl1ps
    Author

    Ryan Cavanaugh (@RyanCavanaugh) Hi, could you please look at this issue and let us know if it will be supported by TypeScript or not? Just the verdict would be fine for now.

    Aliases aside, we would expect at least barrel imports (import { Dog as Dog2 } from 'animals';) to work.

    Please let us know so we can move with our project. Thanks.

  4. hcapp01 commented on May 10, 2020

    @hcapp01

    Sheetal Nandi (@sheetalkamat) it looks like it is not just misleading error message but "project references" does not work with amd module .
    I have hit the same issue with triple slash directives in amd module.

    https://github.com/hcapp01/project-references-demo

    tsc -b
    animals/dog.ts:2:22 - error TS6305: Output file '/Users/hcapp01/code/project-references-demo/lib/core.d.ts' has not been built from source file '/Users/hcapp01/code/project-references-demo/core/utilities.ts'.
    2 /// <reference path="../core/utilities.ts"/>
    ~~~~~~~~~~~~~~~~~~~~

    Found 1 error.

  5. hcapp01 commented on May 16, 2020

    @hcapp01

    It looks like outFile is disabled intentionally. Maybe expose useSourceOfProjectReferenceRedirect as compilerOption can workaround the issue.

    image

  6. RyanCavanaugh commented on Sep 3, 2026

    @RyanCavanaugh
    Member

    This project still reports the four TS6305 errors in TypeScript 6.0.3 when outFile is used (with ignoreDeprecations set to "6.0"). TypeScript 7 did not port outFile, as recorded in #62980; current native TypeScript reports TS5102: Option 'outFile' has been removed.

    #62981 deprecated the classic compiler option, and typescript-go#1381 added the explicit native removed-option diagnostic. The outFile project-reference behavior is therefore retired rather than supported by TypeScript 7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: tsc -bIssues related to build modeFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions