I just tried to reproduce your problem and it works for me.
I followed these steps:
- Create new Gatsby site:
npx gatsby new gatsby-site
- Build site:
npm run build
- Run site:
npm run serve
For example in the Header component propTypes are defined as the following:
Header.propTypes = {
siteTitle: PropTypes.string,
}
Header.defaultProps = {
siteTitle: ``,
}
When inspecting the finished site, you only see defaultProps, not propTypes which is correct
var r = n("q1tI")
, o = n.n(r)
, i = n("Wbzz")
, a = function(e) {
var t = e.siteTitle;
return o.a.createElement("header", {
style: {
background: "rebeccapurple",
marginBottom: "1.45rem"
}
}, o.a.createElement("div", {
style: {
margin: "0 auto",
maxWidth: 960,
padding: "1.45rem 1.0875rem"
}
}, o.a.createElement("h1", {
style: {
margin: 0
}
}, o.a.createElement(i.Link, {
to: "/",
style: {
color: "white",
textDecoration: "none"
}
}, t))))
};
a.defaultProps = {
siteTitle: ""
};
var c = a;
You can also verify by setting siteTitle to PropTypes.number
Header.propTypes = {
siteTitle: PropTypes.number,
}
When running in development using npm run develop you will see a warning in your console
Failed prop type: Invalid prop `siteTitle` of type `string` supplied to `Header`, expected `number`.
You won't see this in production when running npm run build && npm run serve
Note: propTypes and defaultProps is something different.
Have you also checked your Gatsby version? Maybe you are running on an older version
I've tried using these versions (latest at the time of this post)
"dependencies": {
"gatsby": "^2.24.26",
"gatsby-image": "^2.4.14",
"gatsby-plugin-manifest": "^2.4.21",
"gatsby-plugin-offline": "^3.2.21",
"gatsby-plugin-react-helmet": "^3.3.10",
"gatsby-plugin-sharp": "^2.6.24",
"gatsby-source-filesystem": "^2.3.23",
"gatsby-transformer-sharp": "^2.5.12",
"prop-types": "^15.7.2",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-helmet": "^6.1.0"
},