I am a Gatsby newbie and I'm following this tutorial: https://www.gatsbyjs.com/docs/creating-plugins/ to learn to create a gatsby local plugin using react-intl
. I put the plugin in the plugins
folder in the root of the project.
This is the demo code of the plugin (Demo Project Repo: https://github.com/85Ryan/gatsby-local-plugin-demo.git)
// ./src/wrap-page-element.js
import * as React from 'react'
import { IntlProvider } from 'react-intl'
const message = {
welcome: 'Welcome',
home: 'Home',
}
const wrapPageElement = ({ element }) => {
const locale = 'en'
return (
<IntlProvider locale={locale} key={locale} messages={message}>
{element}
</IntlProvider>
)
}
export { wrapPageElement }
// gatsby-browser.js
export { wrapPageElement } from './src/wrap-page-element'
// gatsby-ssr.js
export { wrapPageElement } from './src/wrap-page-element'
When I build the Gatsby site, it crashes with the error WebpackError: [React Intl] Could not find required
intlobject. <IntlProvider> needs to exist in the component ancestry.
But when I publish the plugin to npm, it works fine.
Can anyone help me to find where my problem is?
Thanks!