Graphql: ts-morph now required?

Created on 24 Feb 2020  路  5Comments  路  Source: nestjs/graphql

I'm submitting a...


[x] Regression 
[ ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

ts-morph is required in order to use @nestjs/graphql

Expected behavior


ts-morph is not required in order to use @nestjs/graphql. Our rather large application was working prior to this release without ts-morph, so not sure what changed.

Minimal reproduction of the problem with instructions


Attempting to upgrade from 6.5.5 to 6.6.1 raises the following error:

Error: Cannot find module 'ts-morph'
Require stack:
- /app/node_modules/@nestjs/graphql/dist/graphql-ast.explorer.js
- /app/node_modules/@nestjs/graphql/dist/index.js
- /app/node_modules/@nestjs/graphql/index.js
- /app/src/app.resolver.ts

What is the motivation / use case for changing the behavior?

This is a regression as ts-morph was not required prior to 6.6.1 and it is still listed as an optionalDependency

https://github.com/nestjs/graphql/blob/7a135f87784ca47b50028915655fbc00bac2a7cf/package.json#L74

Environment


"@nestjs/common": "6.11.8",
"@nestjs/core": "6.11.8",
"@nestjs/graphql": "6.6.1",


For Tooling issues:
- Node version: 12.15.0
- Platform:  Mac
- Yarn version: 1.22.0

Others:

search terms: Cannot find module, ts-morph

Most helpful comment

Fixed in 6.6.2. Sorry about this regression!

All 5 comments

Just noticed it now as well. (I'm trying to make my nest app work on aws-lambda now, and have been just surprised that it requires typescript and ts-morph dependencies on a production build.)

When looking at dist/graphql-ast.explorer.js source, it relies on that dep in such ways:

  • const structureKind = mode === 'class' ? ts_morph_1.StructureKind.Class : ts_morph_1.StructureKind.Interface;
  • kind: ts_morph_1.StructureKind.Parameter,

So even though we're "trying" to rely on TS typedefs only there in https://github.com/nestjs/graphql/blob/master/lib/graphql-ast.explorer.ts#L102 , it's making the file rely on actual JS variable data coming from ts-morph package.

From briefly analzing the source code of that file, it seems like that the whole code in that class won't be run anyways until explore() is run which then does await import('ts-morph') ?

If so, then maybe we could just move those StructureKind NewLineKind references to be coming from const { StructureKind, NewLineKind } = await import('ts-morph') ?

I can send a quick PR, if maintainers are ok with such solution.

Fixed in 6.6.2. Sorry about this regression!

@kamilmysliwiec with 6.6.2 I still see:

api_1              | ERROR in ../node_modules/graphql/index.mjs 42:0-48:205
api_1              | Can't reexport the named export 'BREAK' from non EcmaScript module (only default export is available)
api_1              |  @ ../node_modules/@nestjs/graphql/dist/graphql-definitions.factory.js
api_1              |  @ ../node_modules/@nestjs/graphql/dist/index.js
api_1              |  @ ../node_modules/@nestjs/graphql/index.js
api_1              |  @ ./apps/combats/src/app.module.ts
api_1              |  @ ./apps/combats/src/main.ts
api_1              | 
api_1              | ERROR in ../node_modules/graphql/index.mjs 60:0-97:42
api_1              | Can't reexport the named export 'BreakingChangeType' from non EcmaScript module (only default export is available)
api_1              |  @ ../node_modules/@nestjs/graphql/dist/graphql-definitions.factory.js
api_1              |  @ ../node_modules/@nestjs/graphql/dist/index.js
api_1              |  @ ../node_modules/@nestjs/graphql/index.js
api_1              |  @ ./apps/combats/src/app.module.ts
api_1              |  @ ./apps/combats/src/main.ts

This doesn't seem to be related. Please, create a separate issue and create a repository which reproduces your error.

Was this page helpful?
0 / 5 - 0 ratings