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

Express example is not working #2731

Closed
EmrysMyrddin opened this issue Apr 28, 2023 · 1 comment
Closed

Express example is not working #2731

EmrysMyrddin opened this issue Apr 28, 2023 · 1 comment

Comments

@EmrysMyrddin
Copy link
Collaborator

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

@EmrysMyrddin
Copy link
Collaborator Author

Never mind, It seems it something went wrong when pnpm installed dependencies.
After clearing pnpm cache, reinstalling dependencies, it works.

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