Skip to content

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

Open
@diegoarda

Description

@diegoarda

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions