Skip to content

Express example is not working #2731

@EmrysMyrddin

Description

@EmrysMyrddin

Describe the bug

The Express example is not starting after a fresh install:

$ pnpm install && pnpm build
...

$ cd examples/express && pnpm start

> example-express@0.13.6 start /Users/valentin/Dev/Projects/graphql-yoga/examples/express
> ts-node src/index.ts

/Users/valentin/Dev/Projects/graphql-yoga/node_modules/.pnpm/ts-node@10.9.1/node_modules/ts-node/dist/index.js:851
            return old(m, filename);
                   ^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/valentin/Dev/Projects/graphql-yoga/node_modules/.pnpm/tslib@2.5.0/node_modules/tslib/tslib.js from /Users/valentin/Dev/Projects/graphql-yoga/node_modules/.pnpm/@graphql-tools+utils@9.2.1_graphql@16.6.0/node_modules/@graphql-tools/utils/cjs/index.js not supported.
tslib.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename tslib.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /Users/valentin/Dev/Projects/graphql-yoga/node_modules/.pnpm/tslib@2.5.0/node_modules/tslib/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

    at require.extensions.<computed> [as .js] (/Users/valentin/Dev/Projects/graphql-yoga/node_modules/.pnpm/ts-node@10.9.1/node_modules/ts-node/dist/index.js:851:20)
    at Object.<anonymous> (/Users/valentin/Dev/Projects/graphql-yoga/node_modules/.pnpm/@graphql-tools+utils@9.2.1_graphql@16.6.0/node_modules/@graphql-tools/utils/cjs/index.js:3:17)
    at require.extensions.<computed> [as .js] (/Users/valentin/Dev/Projects/graphql-yoga/node_modules/.pnpm/ts-node@10.9.1/node_modules/ts-node/dist/index.js:851:20)
    at Object.<anonymous> (/Users/valentin/Dev/Projects/graphql-yoga/packages/graphql-yoga/dist/cjs/error.js:5:17)
    at require.extensions.<computed> [as .js] (/Users/valentin/Dev/Projects/graphql-yoga/node_modules/.pnpm/ts-node@10.9.1/node_modules/ts-node/dist/index.js:851:20)
    at Object.<anonymous> (/Users/valentin/Dev/Projects/graphql-yoga/packages/graphql-yoga/dist/cjs/index.js:5:18)
    at require.extensions.<computed> [as .js] (/Users/valentin/Dev/Projects/graphql-yoga/node_modules/.pnpm/ts-node@10.9.1/node_modules/ts-node/dist/index.js:851:20)
    at Object.<anonymous> (/Users/valentin/Dev/Projects/graphql-yoga/examples/express/src/app.ts:4:24)
    at m._compile (/Users/valentin/Dev/Projects/graphql-yoga/node_modules/.pnpm/ts-node@10.9.1/node_modules/ts-node/dist/index.js:857:29)
    at require.extensions.<computed> [as .ts] (/Users/valentin/Dev/Projects/graphql-yoga/node_modules/.pnpm/ts-node@10.9.1/node_modules/ts-node/dist/index.js:859:16)
    at Object.<anonymous> (/Users/valentin/Dev/Projects/graphql-yoga/examples/express/src/index.ts:7:15)
    at m._compile (/Users/valentin/Dev/Projects/graphql-yoga/node_modules/.pnpm/ts-node@10.9.1/node_modules/ts-node/dist/index.js:857:29)
    at require.extensions.<computed> [as .ts] (/Users/valentin/Dev/Projects/graphql-yoga/node_modules/.pnpm/ts-node@10.9.1/node_modules/ts-node/dist/index.js:859:16)
    at phase4 (/Users/valentin/Dev/Projects/graphql-yoga/node_modules/.pnpm/ts-node@10.9.1/node_modules/ts-node/dist/bin.js:466:20)
    at bootstrap (/Users/valentin/Dev/Projects/graphql-yoga/node_modules/.pnpm/ts-node@10.9.1/node_modules/ts-node/dist/bin.js:54:12)
    at main (/Users/valentin/Dev/Projects/graphql-yoga/node_modules/.pnpm/ts-node@10.9.1/node_modules/ts-node/dist/bin.js:33:12)
    at Object.<anonymous> (/Users/valentin/Dev/Projects/graphql-yoga/node_modules/.pnpm/ts-node@10.9.1/node_modules/ts-node/dist/bin.js:579:5) {
  code: 'ERR_REQUIRE_ESM'
}
 ELIFECYCLE  Command failed with exit code 1.

Your Example Website or App

https://github.com/dotansimha/graphql-yoga/tree/main/examples/express

Steps to Reproduce the Bug or Issue

  1. Clone the project
  2. run pnpm install
  3. run pnpm build
  4. go to examples/express
  5. run pnpm start

Expected behavior

It should start the express server example.

Screenshots or Videos

No response

Platform

  • OS: macOS 13.3.1
  • NodeJS: v20.0.0
  • @graphql-yoga/* version(s): master

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions