TypeStrong / TypeStrong/ts-loader

ProjectReferences: ts-loader doesnt build dependent projects

Open
#1,005 28 comments 13 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

pinned
Dominant language
TypeScript
Stars
3.5k
Forks
439
Avg merge
17h 17m
Merged PRs (30d)
2

Description

Expected Behaviour

Based on this highly anticipated and recently merged PR: https://github.com/TypeStrong/ts-loader/pull/935 by @sheetalkamat I would expect ts-loader to build dependent projects if projectReferences: true.

Actual Behaviour

Dependent project reference is not built when building project.

The test projectReferencesNotBuilt referenced in the "steps to reproduce" section seems to account for the fact that the dependent project may not already be built. However, the expected output of that test is just the TypeScript error saying the project hasn't been built and to run tsc --build to build the dependent project. I would expect the projectReferences config option to basically run the API equivalent of tsc --build.

Actual application error:

Module build failed (from ../node_modules/ts-loader/index.js):
Error: Could not find output JavaScript file for input assets/scripts/api/api.ts (looked at assets/scripts/lib/api/api.js).
The input file is part of a project reference located at tsconfig.json, so ts-loader is looking for the project’s pre-built output on disk. Try running `tsc --build` to build project references.
    at successLoader (/src/node_modules/ts-loader/dist/index.js:46:19)
    at Object.loader (/src/node_modules/ts-loader/dist/index.js:22:12)
 @ ./portal/assets/scripts/actions/Dashboard.tsx 28:0-129 42:15-37 43:19-37 44:23-45 45:16-41
 @ ./portal/assets/scripts/router.ts
 @ ./portal/assets/scripts/index.tsx
./assets/scripts/api/methods.ts
Steps to Reproduce the Problem

Typescript: v3.6.3
ts-loader: v6.1.0

yarn run comparison-tests --single-test projectReferencesNotBuilt                                                    09/17 15:40:15 121.372s
yarn run v1.17.3
$ tsc --project "./test/comparison-tests" && npm link ./test/comparison-tests/testLib && node test/comparison-tests/run-tests.js --single-test projectReferencesNotBuilt
npm WARN lib@0.0.1 No repository field.
npm WARN lib@0.0.1 No license field.

up to date in 0.276s
found 0 vulnerabilities

/Users/justin/.fnm/node-versions/v12.3.1/installation/lib/node_modules/lib -> /src/ts-loader/test/comparison-tests/testLib
/src/ts-loader/node_modules/lib -> /Users/justin/.fnm/node-versions/v12.3.1/installation/lib/node_modules/lib -> /src/ts-loader/test/comparison-tests/testLib

-------------------------------------------------------------------------

Starting to run test suites...



  projectReferencesNotBuilt
    1) should have the correct output
    ✓ should work with transpileOnly (292ms)


  1 passing (2s)
  1 failing

  1) projectReferencesNotBuilt
       should have the correct output:

      Uncaught AssertionError [ERR_ASSERTION]: bundle.js is different between actual and expected
      + expected - actual

       /*!**********!*/
         !*** ./lib/index.ts ***!
         /**********/
       /*! no static exports found */
      -/***/ (function(module, exports, __webpack_require__) {
      -"use strict";
      -eval("
      -exports.__esModule = true;
      -exports.lib = {
      -    one: 1,
      -    two: 2,
      -    three: 3
      -};
      +/***/ (function(module, exports) {
      +eval("throw new Error(/"Module build failed (fromts-loader):/nError: Could not find output JavaScript file for input lib/index.ts (looked at lib/index.js)./nThe input file is part of a project reference located at lib/tsconfig.json, so ts-loader is looking for the project’s pre-built output on disk. Try running `tsc --build` to build project references./n    at successLoader (ts-loader)/n    at Object.loader (ts-loader)/");
       /# sourceURL=webpack://./lib/index.ts?");
       /***/ })
       /******/ });

      at compareActualAndExpected (test/comparison-tests/create-and-execute-test.js:467:16)
      at /src/ts-loader/test/comparison-tests/create-and-execute-test.js:333:13
      at Array.forEach (<anonymous>)
      at compareFiles (test/comparison-tests/create-and-execute-test.js:329:31)
      at Watching.handler (test/comparison-tests/create-and-execute-test.js:194:9)
      at /src/ts-loader/node_modules/webpack/lib/Watching.js:100:9
      at AsyncSeriesHook.eval [as callAsync] (eval at create (node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
      at AsyncSeriesHook.lazyCompileHook (node_modules/webpack/node_modules/tapable/lib/Hook.js:154:20)
      at Watching._done (node_modules/webpack/lib/Watching.js:99:28)
      at /src/ts-loader/node_modules/webpack/lib/Watching.js:73:19
      at Compiler.emitRecords (node_modules/webpack/lib/Compiler.js:366:39)
      at /src/ts-loader/node_modules/webpack/lib/Watching.js:54:20
      at /src/ts-loader/node_modules/webpack/lib/Compiler.js:352:14
      at AsyncSeriesHook.eval [as callAsync] (eval at create (node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
      at AsyncSeriesHook.lazyCompileHook (node_modules/webpack/node_modules/tapable/lib/Hook.js:154:20)
      at /src/ts-loader/node_modules/webpack/lib/Compiler.js:349:27
      at done (node_modules/neo-async/async.js:2854:11)
      at /src/ts-loader/node_modules/neo-async/async.js:2805:7
      at /src/ts-loader/node_modules/graceful-fs/graceful-fs.js:45:10
      at FSReqCallback.oncomplete (fs.js:137:23)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the projectReferencesNotBuilt comparison test in test/comparison-tests and the loader entry points shown in index.js and dist/index.js. Reproduce it with yarn run comparison-tests --single-test projectReferencesNotBuilt, then use the expected bundle output to verify that dependent project references build instead of producing the pre-built-output error.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, webpack
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.