gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.28k stars 10.31k forks source link

Missing onError handler for invocation 'building-schema', error was 'Error: Cannot create as TypeComposer the following value: Date.' #38750

Open SergioMaurySterling opened 11 months ago

SergioMaurySterling commented 11 months ago

Preliminary Checks

Description

Gatsby project

Comments> The project is using NPM, cannot be changed to yarn, it will imply in multiple other errors/issues.

The error> sams@192 project % npm run start

project@1.0.59 start NODE_ENV=development npm run develop

project@1.0.59 develop /Users/sams/Desktop/project bash -h scripts/generate_manifest.sh && gatsby develop

/Users/sams/Desktop/project/node_modules/gatsby-recipes/dist/graphql-server /server.js:52 var remarkMdx = require('remark-mdx'); ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/sams/Desktop/project/node_modules/remark-mdx/index.js from /Users/sams/Desktop/project/nodemodules/gatsby-recipes/dist/graphql-server /server.js not supported. Instead change the require of index.js in /Users/sams/Desktop/project/node modules/gatsby-recipes/dist/graphql-server/server.js to a dynamic import() which is available in all CommonJS modules. at Object. (/Users/sams/Desktop/project/node_modules/gatsby- recipes/dist/graphql-server/server.js:52:17) { code: 'ERR_REQUIRE_ESM' }

success open and validate gatsby-configs - 0.125s success load plugins - 0.996s success onPreInit - 0.065s success initialize cache - 0.017s success copy gatsby files - 0.064s success onPreBootstrap - 0.024s success createSchemaCustomization - 0.008s success Checking for changed pages - 0.005s success source and transform nodes - 0.315s

ERROR

Missing onError handler for invocation 'building-schema', error was 'Error: Cannot create as TypeComposer the following value: Date.'. Stacktrace was 'Error: Cannot create as TypeComposer the following value: Date. at SchemaComposer.createTempTC (/Users/sams/Desktop/project/node_module s/graphql-compose/lib/SchemaComposer.js:365:11) at SchemaComposer.addAsComposer (/Users/sams/Desktop/project/node_modul es/graphql-compose/lib/SchemaComposer.js:563:27) at createSchemaComposer (/Users/sams/Desktop/project/node_modules/gatsb y/src/schema/schema-composer.js:16:18) at build (/Users/sams/Desktop/project/node_modules/gatsby/src/schema/in dex.js:104:26) at buildSchema (/Users/sams/Desktop/project/node_modules/gatsby/src/ser vices/build-schema.ts:19:3)'

⠇ building schema

Reproduction Link

https://codesandbox.io/p/devbox/github/gatsbyjs/gatsby-starter-minimal

Steps to Reproduce

  1. nvm install
  2. nvm use
  3. npm install --legacy-peer-deps
  4. npm run start

Expected Result

Project running on port localhost:8000

Actual Result

Missing onError handler for invocation 'building-schema', error was 'Error: Cannot create as TypeComposer the following value: Date.'. Stacktrace was 'Error: Cannot create as TypeComposer the following value: Date.

Environment

System:
    OS: macOS 13.0
    CPU: (16) x64 Apple M1
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.20.2 - ~/.nvm/versions/node/v16.20.2/bin/node
    npm: 8.19.4 - ~/.nvm/versions/node/v16.20.2/bin/npm
  Browsers:
    Chrome: 119.0.6045.199
    Safari: 16.1
  npmPackages:
    gatsby: ^2.32.12 => 2.32.13
    gatsby-image: 2.4.5 => 2.4.5
    gatsby-plugin-manifest: 2.4.9 => 2.4.9
    gatsby-plugin-offline: 3.2.7 => 3.2.7
    gatsby-plugin-react-helmet: 3.3.2 => 3.3.2
    gatsby-plugin-s3: 0.3.4 => 0.3.4
    gatsby-plugin-sharp: 2.6.9 => 2.6.9
    gatsby-source-filesystem: 2.3.8 => 2.3.8
    gatsby-transformer-sharp: 2.5.3 => 2.5.3
  npmGlobalPackages:
    gatsby-cli: 5.12.4

Config Flags

plugins: [ 'gatsby-plugin-react-helmet', { resolve: 'gatsby-source-filesystem', options: { name: 'images', path: ${__dirname}/src/images, }, }, 'gatsby-transformer-sharp', 'gatsby-plugin-sharp', { resolve: 'gatsby-plugin-manifest', options: { name: 'gatsby-starter-default', short_name: 'starter', start_url: '/', display: 'minimal-ui', icon: 'src/images/favicon-logo.png', }, }, ],

codewithriza commented 11 months ago

Issue Resolution Suggestion

Hello SergioMaurySterling

Thank you for reporting this issue. From the error message provided, it seems that there's a conflict between ES Modules (require()) and CommonJS (import()), specifically with the usage of remark-mdx.

To resolve this, the error message suggests changing the require() call to a dynamic import() in the affected file server.js within gatsby-recipes:

From:

var remarkMdx = require('remark-mdx');

To:

var remarkMdx = import('remark-mdx');

Please attempt this modification and check if it resolves the issue. If the problem persists or if you encounter related errors, please let us know. Additionally, ensure to review other parts of the codebase for similar incompatibilities.

Let me know if you need further assistance.

Best regards, Riza