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

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

Closed
OliverJAsh opened this issue Jun 10, 2021 · 5 comments
Labels

Comments

@OliverJAsh
Copy link

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

@johnnyreilly
Copy link
Member

Mystery. We backported this to V8 #1287

Don't know that other changes on v9 would have bearing on this..

@OliverJAsh
Copy link
Author

OliverJAsh commented Jun 10, 2021

Any suggestions where I could start debugging this? Why would it try to type check a source file (not a type def file) inside of node_modules? 🤔

@johnnyreilly
Copy link
Member

I wonder if there's any link between this and #1226 - cc @berickson1

In terms of debugging it's probably worth following these instructions: https://github.com/TypeStrong/ts-loader/blob/main/CONTRIBUTING.md#debugging

@stale
Copy link

stale bot commented Apr 17, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Apr 17, 2022
@stale
Copy link

stale bot commented Apr 28, 2022

Closing as stale. Please reopen if you'd like to work on this further.

@stale stale bot closed this as completed Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants