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

Build command not generate JS file types correctly with commonjs #5343

Open
4 tasks
diegoarda opened this issue Apr 19, 2023 · 0 comments
Open
4 tasks

Build command not generate JS file types correctly with commonjs #5343

diegoarda opened this issue Apr 19, 2023 · 0 comments

Comments

@diegoarda
Copy link

Issue workflow progress

Progress of the issue based on the
Contributor Workflow

  • 1. The issue provides a reproduction available on
    Github

Make sure to fork this template and run yarn generate in the terminal.

Please make sure Mesh package versions under package.json matches yours.

  • 2. A failing test has been provided
  • 3. A local solution has been provided
  • 4. A pull request is pending review

Describe the bug

When we launch build command of the cli with commonjs and the flag --fileType=js

mesh build --fileType=js

the build commands fails because it are not treating files as commonjs library. Moreover, without fileType=js it only generates ts files and is not traspiling to js files.

To Reproduce Steps to reproduce the behavior:

  1. In the repository, change build command to mesh build --fileType=js
  2. Execute npm run build
  3. Launch the next error:

💥 🕸️ Mesh - Wiki Failed to generate the schema C:\Inditex\Projects\mesh\openapi-javascript-wiki.mesh\sources\Wiki\schemaWithAnnotations.js:2
import { buildASTSchema } from 'graphql';
^^^^^^

SyntaxError: Cannot use import statement outside a module
at internalCompileFunction (node:internal/vm:73:18)
at wrapSafe (node:internal/modules/cjs/loader:1195:20)
at Module._compile (node:internal/modules/cjs/loader:1239:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1329:10)
at Object.require.extensions. [as .js] (C:\Inditex\Projects\mesh\openapi-javascript-wiki\node_modules\ts-node\src\index.ts:1608:43)
at Module.load (node:internal/modules/cjs/loader:1133:32)
at Function.Module._load (node:internal/modules/cjs/loader:972:12)
at Module.require (node:internal/modules/cjs/loader:1157:19)
at require (node:internal/modules/helpers:119:18)
at C:\Inditex\Projects\mesh\openapi-javascript-wiki\node_modules@graphql-mesh\utils\cjs\defaultImportFn.js:29:74
💥 🕸️ Mesh Error: Schemas couldn't be generated successfully. Check for the logs by running Mesh with DEBUG=1 environmental variable to get more verbose output.
at getMesh (C:\Inditex\Projects\mesh\openapi-javascript-wiki\node_modules@graphql-mesh\runtime\cjs\get-mesh.js:167:15)
at async Object.handler (C:\Inditex\Projects\mesh\openapi-javascript-wiki\node_modules@graphql-mesh\cli\cjs\index.js:311:53)

Expected behavior

Generate correct commonjs package with js files (not only TS files).

Environment:

  • OS: Windows 10
  • @graphql-mesh/cli: 0.82.33
  • "@graphql-mesh/openapi: 0.36.0
  • NodeJS: 19.8.1

Additional context

It happens with other samples of commonjs. It seems that schemaWithAnnotations.js file is not treated correctly as commonjs file and it treats it as ESM module.

This was referenced Apr 30, 2024
This was referenced May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant