Skip to content

Commit

Permalink
Better check for MODULE_NOT_FOUND error
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAMathews committed Oct 5, 2016
1 parent 2b835f5 commit c1a368e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
5 changes: 1 addition & 4 deletions lib/utils/api-runner-browser.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
const Promise = require(`bluebird`)
const path = require(`path`)
import invariant from 'invariant'
import _ from 'lodash'

module.exports = (api, args, defaultReturn) => {
let gatsbyBrowser
try {
gatsbyBrowser = require(`gatsby-browser`)
} catch (e) {
console.log('error', e)
if (e.code !== `MODULE_NOT_FOUND` && !_.includes(e.Error, `gatsby-browser`)) {
if (e.toString().indexOf(`gatsby-browser`) !== -1) {
console.log(`Couldn't open your gatsby-browser.js file`)
console.log(e)
}
}
console.log('gatsbyBrowser module + api', gatsbyBrowser, api)
if (gatsbyBrowser && gatsbyBrowser[api]) {
const result = gatsbyBrowser[api](args)
if (!result) {
Expand Down
6 changes: 3 additions & 3 deletions lib/utils/api-runner-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ const Promise = require(`bluebird`)
const path = require(`path`)
import invariant from 'invariant'
import _ from 'lodash'
import chalk from 'chalk'

module.exports = async (api, args, defaultReturn) => {
let gatsbyNode
try {
gatsbyNode = require(`${path.resolve(`.`)}/gatsby-node`)
} catch (e) {
console.log('error', e)
if (e.code !== `MODULE_NOT_FOUND` && !_.includes(e.Error, `gatsby-node`)) {
console.log(`Couldn't open your gatsby-node.js file`)
if (/*e.code !== `MODULE_NOT_FOUND` &&*/ !_.includes(e.toString(), `gatsby-node`)) {
console.log(chalk.bold.red(`Couldn't open your gatsby-node.js file`))
console.log(e)
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/api-runner-ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = (api, args, defaultReturn) => {
try {
gatsbySSR = require(`gatsby-ssr`)
} catch (e) {
if (e.code !== `MODULE_NOT_FOUND` && !_.includes(e.Error, `gatsby-browser`)) {
if (/*e.code !== `MODULE_NOT_FOUND` &&*/ !_.includes(e.toString(), `gatsby-ssr`)) {
console.log(`Couldn't open your gatsby-browser.js file`)
console.log(e)
}
Expand Down

0 comments on commit c1a368e

Please sign in to comment.