Skip to content

Project references and v8 (webpack v4): JS files in node_modules should not be type checked #1338

@OliverJAsh

Description

@OliverJAsh

Expected Behaviour

When I run tsc --build, TS does not error.

Similarly, when I run webpack, TS does not error.

Actual Behaviour

When I run tsc --build, TS does not error.

When I run webpack, TS errors due to a type error inside of a JS source file which lives in node_modules.

Steps to Reproduce the Problem

I have a reduced test case but there are still too many steps to list here, so instead I'll just share the link:

https://github.com/OliverJAsh/ts-loader-project-references-js-node-modules

Running tsc --build

$ rm -rf target-tsc dist && tsc --build app/tsconfig.json --verbose
[14:30:54] Projects in this build:
    * shared/tsconfig.json
    * app/tsconfig.json

[14:30:54] Project 'shared/tsconfig.json' is out of date because output file 'target-tsc/shared/foo.js' does not exist

[14:30:54] Building project '/Users/oliverash/Development/ts-loader-project-references-js-node-modules/shared/tsconfig.json'...

[14:30:55] Project 'app/tsconfig.json' is out of date because output file 'target-tsc/app/index.js' does not exist

[14:30:55] Building project '/Users/oliverash/Development/ts-loader-project-references-js-node-modules/app/tsconfig.json'...

Running webpack

$ rm -rf target-tsc dist && webpack
ts-loader: Using [email protected] and /Users/oliverash/Development/ts-loader-project-references-js-node-modules/app/tsconfig.json
Using SolutionBuilder api
message TS6355: Projects in this build:
    * ../shared/tsconfig.json

message TS6352: Project '../shared/tsconfig.json' is out of date because output file '../target-tsc/shared/foo.js' does not exist

message TS6358: Building project '/Users/oliverash/Development/ts-loader-project-references-js-node-modules/shared/tsconfig.json'...

node_modules/assert-never/index.js(28,22): error TS7006: Parameter 'value' implicitly has an 'any' type.

node_modules/assert-never/index.js(28,29): error TS7006: Parameter 'noThrow' implicitly has an 'any' type.

shared/foo.ts(1,20): error TS6307: File '/Users/oliverash/Development/ts-loader-project-references-js-node-modules/node_modules/assert-never/index.js' is not listed within the file list of project '/Users/oliverash/Development/ts-loader-project-references-js-node-modules/shared/tsconfig.json'. Projects must list all files or use an 'include' pattern.

Found 3 errors. Watching for file changes.


Hash: 2602b846fdcd458a07b5
Version: webpack 4.46.0
Time: 1326ms
Built at: 10/06/2021 14:31:43
                                    Asset      Size  Chunks  Chunk Names
             ../target-tsc/app/index.d.ts  11 bytes
../target-tsc/shared/tsconfig.tsbuildinfo  1.56 KiB
                                  main.js  1.67 KiB       0  main
Entrypoint main = main.js
[0] ./app/index.ts 90 bytes {0} [built]
[1] ./shared/foo.ts 724 bytes {0} [built] [failed] [2 errors]

WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/configuration/mode/

ERROR in ./shared/foo.ts
Module build failed (from ./node_modules/ts-loader/index.js):
Error: TypeScript emitted no output for /Users/oliverash/Development/ts-loader-project-references-js-node-modules/shared/foo.ts. The most common cause for this is having errors when building referenced projects.
    at makeSourceMapAndFinish (/Users/oliverash/Development/ts-loader-project-references-js-node-modules/node_modules/ts-loader/dist/index.js:53:18)
    at successLoader (/Users/oliverash/Development/ts-loader-project-references-js-node-modules/node_modules/ts-loader/dist/index.js:40:5)
    at Object.loader (/Users/oliverash/Development/ts-loader-project-references-js-node-modules/node_modules/ts-loader/dist/index.js:23:5)
 @ ./app/index.ts 3:12-36

ERROR in /Users/oliverash/Development/ts-loader-project-references-js-node-modules/node_modules/assert-never/index.js
[tsl] ERROR in /Users/oliverash/Development/ts-loader-project-references-js-node-modules/node_modules/assert-never/index.js(28,22)
      TS7006: Parameter 'value' implicitly has an 'any' type.

ERROR in /Users/oliverash/Development/ts-loader-project-references-js-node-modules/node_modules/assert-never/index.js
[tsl] ERROR in /Users/oliverash/Development/ts-loader-project-references-js-node-modules/node_modules/assert-never/index.js(28,29)
      TS7006: Parameter 'noThrow' implicitly has an 'any' type.

ERROR in /Users/oliverash/Development/ts-loader-project-references-js-node-modules/shared/foo.ts
./shared/foo.ts 1:19-33
[tsl] ERROR in /Users/oliverash/Development/ts-loader-project-references-js-node-modules/shared/foo.ts(1,20)
      TS6307: File '/Users/oliverash/Development/ts-loader-project-references-js-node-modules/node_modules/assert-never/index.js' is not listed within the file list of project '/Users/oliverash/Development/ts-loader-project-references-js-node-modules/shared/tsconfig.json'. Projects must list all files or use an 'include' pattern.

Location of a Minimal Repository that Demonstrates the Issue.

See above.


I tested this with v9 and webpack v5 and I could not reproduce the error—see branch webpack-5+ts-loader-9 in the reduced test case.

Unfortunately upgrading to webpack v5 isn't an option for us right now. In any case it would be good to understand what changed in v9 (maybe we can backport the fix), and hopefully this bug report will still be useful to anyone else who is using v8.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions