Open tmtron opened 5 years ago
It sounds like ncc is trying to read tsconfig.json
for both .js
and .ts
source files when it should only look for tsconfig.json
when the source file is .ts
(or possibly .tsx
.
@guybedford Can you explain why this was changed?
Nothing in ncc itself that does the tsconfig.json
lookup has changed.
But because ncc builds its dependencies of ts-loader and tsconfig-paths, it could be due to an update of these dependencies in the release that cases the problem.
@johnnyreilly would value your thoughts on what this might be that the tsconfig lookup is going further up the folder hierarchy than previously, and if there is a configuration option in ncc that could resolve this?
Hey @guybedford,
I'm afraid I'm just leaving on my holidays and so I'm not going to spare too much time right now.
I've a couple of quick thoughts before I go though:
It looks like a change in the version of being used by ncc may be the cause of this? Which version change triggered this do you know? It's not obvious from "0.17.4 - but now fails with 0.18.5." which ts-loader versions are in play.
it's possible this may be related to the (excellent😄) work @andrewbranch did to fix a number of minor bugs in ts-loader https://github.com/TypeStrong/ts-loader/releases/tag/v6.0.1
Though given the date on this issue maybe that's not the case.
Thanks for the response here @johnnyreilly, we'll see if we can track it down further here first then.
@tmtron to find the root cause here we'll need to do a bisect on the dependency build. And for that we'll need a reliable replication. If you're able to share a simple repo that demonstrates the problem that would help a lot to get there, otherwise I will come around on this when I'm looking the TypeScript-specific stuff further in about a week or so.
I don' t have the time to make a reproduction repo now. Bisect is less work, so I've tried that, but came to a strange result.
It seems that I now get the same issue also with ncc 0.17.4 - so my first thought, that the ncc version caused the issue is wrong: it seems that the issue is not caused directly by code changes in ncc, but by some other dependency that has changed.
on our CI-server I found a side-branch where I see one build that still works and the next one fails (on 24th, Aprli, 1 hour apart).
unfortunately the package-lock files are difficult to compare. are there any other dependencies (besides ts-loader) in the package-lock that I should look for? I could also post the package-lock files somewhere if this helps.
Can someone please confirm my basic understanding of the ncc build:
dist/apps/server/tsconfig-json
node_modules
folder where it will search for dependencies used in my main.js file (I guess it scanns the require
statements)tsconfig.json
file: this is a bug: it should ignore this file, since I feed a main.js
file to it and not any ts filesfor some reason, it also picks up the top-level tsconfig.json file: this is a bug: it should ignore this file, since I feed a main.js file to it and not any ts files
ncc will always read any tsconfig.json
file and apply it, even for .js
-only builds unfortunately, due to the way we plug in the TypeScript resolver. We could look at only applying the TypeScript resolver when loading a TypeScript module certainly.
@guybedford thanks for the response.
I can live with deleting my tsconfig
files during the ci-build before starting ncc - but it would be great if you could improve the docs, so that this fact is clear - especially for new users.
Feel free to close this issue.
First, a related question that could help me: Where is the documentation for ncc? The readme file leaves many open question (at least for me as a beginner). And due to this lack of documentation I don't even know how ncc is supposed to work or which questions to ask. So I'm afraid, I must explain the whole use-case.
The build on our CI server was still okay with version 0.17.4 - but now fails with 0.18.5.
To me it seems, that ncc is now somehow finding our top-level
tsconfig.json
file and it tries to build the whole source code - which will not work, because we have a mono-repo and thus have many differenttsconfig.json
files.This is how our code is organized:
tsconfig.json
- top level ts configangular.json
apps
dirclient
tsconfig.app.json
tsconfig.json
tsconfig.spec.json
server
tsconfig.json
libs
dirshared
node_modules
dirdist
dirapps
server
main.js
- created by the prod buildtsconfig-json
- created by our ci-script for ncc - content from your readme fileThe ci script will first do a regular
ng build
of the server app which createsdist/apps/server/main.js
. Then the ci script will cd toapps/server/
and executencc build main.js --minify --out ncc
to buildncc/index.js
. It seems that the newer ncc version will traverse the folder tree up, find the top-leveltsconfig.json
file and then tries to compile all source code: e.g. inapps/client/...
- which will fail, because the top-leveltsconfig.json
file is not suitable for that source code.As a workaround I tried to delete the top-level
tsconfig.json
file - then the build works.Questions:
main.js
file?tsconfig.json
, when there is atsconfig.json
file in the current directory?tsconfig.json
file it should use?