Skip to content

pluginOptionsSchema not working when using typescript #37319

Closed
@klase

Description

@klase

Preliminary Checks

Description

Gatsby is not picking up the default values nor validating the plugin schema in a gatsby-node.ts file

export const pluginOptionsSchema: GatsbyNode["pluginOptionsSchema"] = ({
  Joi,
}) => {
  return Joi.object({
    siteId: Joi.string().required(),
    templatePath: Joi.string()
      .default("/src/templates")
  });
};

export const onPreInit: GatsbyNode["onPreInit"] = (args, options) => {
  console.log("options: ", options);
 // options does NOT contain default values, nor is validation on required options performed
};

but if I change it to plain js (gatsby-node.js) with commonjs exports everything's fine:

exports.pluginOptionsSchema = ({ Joi }) => {
  return Joi.object({
    siteId: Joi.string().required(),
    templatePath: Joi.string()
      .default("/src/templates")
  });
};

exports.onPreInit = (args, options) => {
  console.log("options: ", options);
 // options contain default values as expected
};

Reproduction Link

see code

Steps to Reproduce

  1. Create plugin in /plugins/test-plugin
  2. Add gatsby-node.ts with above code
  3. Run gatsby develop
    ...

Expected Result

Validation should be performed on the plugin options schema, and default option values set

Actual Result

No defaults are set, and validation is not performed

Environment

System:
    OS: macOS 12.5
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.12.1 - ~/.nvm/versions/node/v18.12.1/bin/node
    Yarn: 1.22.5 - ~/.yarn/bin/yarn
    npm: 8.19.2 - ~/.nvm/versions/node/v18.12.1/bin/npm
  Browsers:
    Chrome: 108.0.5359.124
    Firefox: 107.0.1
    Safari: 15.6
  npmPackages:
    gatsby: ^5.3.3 => 5.3.3
    gatsby-plugin-google-gtag: ^5.2.0 => 5.2.0
    gatsby-plugin-image: ^3.2.0 => 3.2.0
    gatsby-plugin-manifest: ^5.2.0 => 5.2.0
    gatsby-plugin-root-import: ^2.0.9 => 2.0.9
    gatsby-plugin-sharp: ^5.2.0 => 5.2.0
    gatsby-plugin-sitemap: ^6.0.0 => 6.2.0
    gatsby-plugin-styled-components: ^6.0.0 => 6.2.0
    gatsby-source-filesystem: ^5.2.0 => 5.2.0
    gatsby-transformer-sharp: ^5.2.0 => 5.2.0
  npmGlobalPackages:
    gatsby: 5.3.3

Config Flags

No response

Metadata

Metadata

Assignees

Labels

status: confirmedIssue with steps to reproduce the bug that’s been verified by at least one reviewer.topic: coreRelates to Gatsby's core (e.g. page loading, reporter, state machine)type: bugAn issue or pull request relating to a bug in Gatsby

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions