nestjs / graphql

GraphQL (TypeScript) module for Nest framework (node.js) 🍷
https://docs.nestjs.com/graphql/quick-start
MIT License
1.46k stars 396 forks source link

Error: Cannot find module 'ts-morph' #1137

Closed liudonghua123 closed 3 years ago

liudonghua123 commented 4 years ago

Bug Report

Current behavior

I want to just run the graphql example in this repo, so I cloned this repo, and cd sample\12-graphql-schema-first, executed yarn and npx ts-node src\generate-typings.ts, then I got the following errors.

D:\code\node\nest\sample\12-graphql-schema-first>yarn
yarn install v1.22.5
info No lockfile found.
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] Resolving packages...
warning @nestjs/cli > webpack > watchpack > watchpack-chokidar2 > chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
warning @nestjs/cli > webpack > watchpack > watchpack-chokidar2 > chokidar > fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
warning @nestjs/cli > webpack > micromatch > snapdragon > source-map-resolve > resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
warning @nestjs/cli > webpack > micromatch > snapdragon > source-map-resolve > urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
warning jest > jest-cli > jest-config > jest-environment-jsdom > jsdom > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
warning jest > jest-cli > jest-config > jest-environment-jsdom > jsdom > request > har-validator@5.1.5: this
[2/4] Fetching packages...
info fsevents@2.1.3: The platform "win32" is incompatible with this module.
info "fsevents@2.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@1.2.13: The platform "win32" is incompatible with this module.
info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "@nestjs/graphql > @nestjs/mapped-types@0.0.5" has incorrect peer dependency "class-transformer@^0.2.3".
warning "@nestjs/graphql > apollo-server-core > graphql-upload@8.1.0" has incorrect peer dependency "graphql@0.13.1 - 14".
warning "@nestjs/graphql > @apollo/gateway > apollo-graphql@0.4.5" has incorrect peer dependency "graphql@^14.2.1".
warning " > graphql-subscriptions@1.1.0" has incorrect peer dependency "graphql@^0.10.5 || ^0.11.3 || ^0.12.0 || ^0.13.0 || ^14.0.0".
warning " > @nestjs/schematics@7.1.1" has incorrect peer dependency "typescript@^3.4.5".
[4/4] Building fresh packages...
success Saved lockfile.
Done in 468.32s.

D:\code\node\nest\sample\12-graphql-schema-first>npx ts-node src\generate-typings.ts
(node:34944) UnhandledPromiseRejectionWarning: Error: Cannot find module 'ts-morph'
Require stack:
- D:\code\node\nest\sample\12-graphql-schema-first\node_modules\@nestjs\graphql\dist\graphql-ast.explorer.js
- D:\code\node\nest\sample\12-graphql-schema-first\node_modules\@nestjs\graphql\dist\federation\graphql-federation.module.js
- D:\code\node\nest\sample\12-graphql-schema-first\node_modules\@nestjs\graphql\dist\federation\index.js
- D:\code\node\nest\sample\12-graphql-schema-first\node_modules\@nestjs\graphql\dist\index.js
- D:\code\node\nest\sample\12-graphql-schema-first\node_modules\@nestjs\graphql\index.js
- D:\code\node\nest\sample\12-graphql-schema-first\src\generate-typings.ts
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1080:15)
    at Function.Module._load (internal/modules/cjs/loader.js:923:27)
    at Module.require (internal/modules/cjs/loader.js:1140:19)
    at require (internal/modules/cjs/helpers.js:75:18)
    at D:\code\node\nest\sample\12-graphql-schema-first\node_modules\@nestjs\graphql\dist\graphql-ast.explorer.js:18:61
(Use `node --trace-warnings ...` to show where the warning was created)
(node:34944) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:34944) [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.

D:\code\node\nest\sample\12-graphql-schema-first>

Input Code

Not involved

Expected behavior

No errors

Possible Solution

Using npm instead of yarn.

Environment


Nest version: 7.4.4


For Tooling issues:
- Node version: XX  
- Platform:  

```
D:\code\node\nest\sample\12-graphql-schema-first>node -v
v14.8.0

D:\code\node\nest\sample\12-graphql-schema-first>yarn -v
1.22.5

D:\code\node\nest\sample\12-graphql-schema-first>ver

Microsoft Windows [Version 10.0.19041.450]

D:\code\node\nest\sample\12-graphql-schema-first>
```

Others:

kamilmysliwiec commented 3 years ago

ts-morph is an optional package (for example, because it's not needed for the code first approach). In this case, you must explicitly install it.

dallen4 commented 3 years ago

@kamilmysliwiec if the ts-morph package is required for schema first, can it be added to the example project?

liudonghua123 commented 3 years ago

It seems ok when using npm instead of yarn. Maybe the dependence resolve around optional package is different. npm will install the related optional package while yarn will not install.

SEBIIWA commented 3 years ago

I am using npm and encountered the same problem

kamilmysliwiec commented 3 years ago

https://github.com/nestjs/graphql/issues/1621#issuecomment-878199238