ncc: nestJS + graphql code first + ncc = Error: Generating schema error
I would like to use ncc to reduce my docker image size by removing the dependency to node_modules but I have a runtime issue :
[Nest] 19257 - 05/08/2019, 10:44 AM [InstanceLoader] ConfigModule dependencies initialized +18ms
[Nest] 19257 - 05/08/2019, 10:44 AM [InstanceLoader] ApiModule dependencies initialized +1ms
[Nest] 19257 - 05/08/2019, 10:44 AM [InstanceLoader] GraphQLModule dependencies initialized +1ms
[Nest] 19257 - 05/08/2019, 10:44 AM [RoutesResolver] ConfigController {/api/config}: +4ms
[Nest] 19257 - 05/08/2019, 10:44 AM [RouterExplorer] Mapped {/, GET} route +2ms
(node:19257) UnhandledPromiseRejectionWarning: Error: Generating schema error
at Function.<anonymous> (/home/**index.js:287962:27)
at Generator.next (<anonymous>)
at fulfilled (/home/**/index.js:116122:62)
at internalTickCallback (internal/process/next_tick.js:77:7)
at process._tickCallback (internal/process/next_tick.js:47:5)
at Function.Module.runMain (internal/modules/cjs/loader.js:778:11)
at startup (internal/bootstrap/node.js:300:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:826:3)
(node:19257) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:19257) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
It seems there is still a dependency to the node_modules because it works with it…
I have some compilation issue too but I don’t know if it related:
➜ start-on-time git:(cleanup-ci-configs) ✗ npx ncc build ./dist/apps/api/main.js -o ./dist/apps/api
ncc: Version 0.18.3
ncc: Compiling file index.js
ncc: Module directory "/home/**/node_modules/chokidar/lib" attempted to require "fsevents" but could not be resolved, assuming external.
ncc: Module directory "/home/**/node_modules/ws/lib" attempted to require "utf-8-validate" but could not be resolved, assuming external.
ncc: Module directory "/home/**/node_modules/ws/lib" attempted to require "bufferutil" but could not be resolved, assuming external.
ncc: Module directory "/home/**/node_modules/@nestjs/core" attempted to require "@nestjs/microservices" but could not be resolved, assuming external.
ncc: Module directory "/home/**/node_modules/@nestjs/core" attempted to require "@nestjs/microservices" but could not be resolved, assuming external.
Main libraries version:
- nest : 6.1
- ncc: 0.18.2
- graphql: 14.2
- graphql-type: 1.1
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 3
- Comments: 20 (2 by maintainers)
Just published 6.4.1 fix that will call
requireinloadPackage()@jogelin@kamilmysliwiec It works ! Thx !!
Just a little remark, do you load the library twice then ?
@darklam not for the moment, it is not so bad to have a docker image = 943mo 😄
@gimyboya From my understanding, the issue is that the resulting “compiled” index.js file still has some external dependencies to graphql and type-graphql packages. So the way I fixed it is by taking the output dist from ncc, initializing an empty npm package and installing the graphql and type-graphql packages, so the dependencies are resolved correctly and everything works. Mind you, this was done in docker, so I am not sure how it will work with other environments. Also, I had problems compiling my ts nestjs server with the newer ncc releases, so I am currently still using the 0.18.5 version. In short the commands would look like:
Then, the index file inside dist should run correctly. Hope this helps you, if you have any more questions feel free to reply.
EDIT: I just saw I said git repo in my previous reply, it was just my mind playing games, I actually meant empty npm package. Sorry if it caused any confusion.