Skip to content

Project with project references and outFile fails to build #34846

@ecl1ps

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: tsc -bIssues related to build mode

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions