File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
packages/gatsby/src/internal-plugins/internal-data-bridge Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -122,10 +122,18 @@ exports.sourceNodes = ({ boundActionCreators, store }) => {
122122 `gatsby-config.js`
123123 )
124124 chokidar . watch ( pathToGatsbyConfig ) . on ( `change` , ( ) => {
125- // Delete require cache so we can reload the module.
126- delete require . cache [ require . resolve ( pathToGatsbyConfig ) ]
127- const config = require ( pathToGatsbyConfig )
128- createGatsbyConfigNode ( config )
125+ const oldCache = require . cache [ require . resolve ( pathToGatsbyConfig ) ]
126+ try {
127+ // Delete require cache so we can reload the module.
128+ delete require . cache [ require . resolve ( pathToGatsbyConfig ) ]
129+ const config = require ( pathToGatsbyConfig )
130+ createGatsbyConfigNode ( config )
131+ } catch ( e ) {
132+ // Restore the old cache since requiring the new gatsby-config.js failed.
133+ if ( oldCache !== undefined ) {
134+ require . cache [ require . resolve ( pathToGatsbyConfig ) ] = oldCache
135+ }
136+ }
129137 } )
130138}
131139
You can’t perform that action at this time.
0 commit comments