gatsby
gatsby copied to clipboard
Documentation is wrong for initialising the plugin.
Preliminary Checks
- [X] This issue is not a duplicate. Before opening a new issue, please search existing issues: https://github.com/gatsbyjs/gatsby/issues
- [X] This issue is not a question, feature request, RFC, or anything other than a bug report. Please post those things in GitHub Discussions: https://github.com/gatsbyjs/gatsby/discussions
Summary
When including the code as per the docs it actually errors saying adapter is not a function.
const adapter = require('gatsby-adapter-netlify');
module.exports = {
adapter: adapter({
excludeDatastoreFromEngineFunction: false,
}),
}
Im assuming this is because if you import it will grab the .default
manually
Steps to Resolve this Issue
- use import instead
- add
.default
at the end of require
Same issue with import
and an esm gatsby-config.mjs
file (supported since Gatsby 5.3).
I tried import adapter from 'gatsby-adapter-netlify';
and import { default as adapter } from 'gatsby-adapter-netlify';
but get the following error:
ERROR #10123 API.CONFIG.LOADING
We encountered an error while trying to load your site's gatsby-config. Please fix the error and try again.
TypeError: adapter is not a function
- gatsby-config.mjs:13
{project-path}/gatsby-config.mjs:13:12
- module_job:194 ModuleJob.run
node:internal/modules/esm/module_job:194:25
Same issue here, can't make it work with gatsby 5.12.9
error We encountered an error while trying to load your site"s gatsby-config. Please fix the error and try again.
TypeError: adapter is not a function
const adapter = require("gatsby-adapter-netlify").default
as @darylthornhill suggested is propsed in PR #38816
Is there any reason why this isnt fixed in the docs? Annoying to search around for basic things like that....