Skip to content

Commit

Permalink
fix(babel-preset-gatsby): Show a helpful error when used in the wrong…
Browse files Browse the repository at this point in the history
… environment (#11555)
  • Loading branch information
paulmelnikow authored and pieh committed Feb 5, 2019
1 parent 0269981 commit adf06e5
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/babel-preset-gatsby/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@ const resolve = m => require.resolve(m)
const loadCachedConfig = () => {
let pluginBabelConfig = {}
if (process.env.NODE_ENV !== `test`) {
pluginBabelConfig = require(path.join(
process.cwd(),
`./.cache/babelState.json`
))
try {
pluginBabelConfig = require(path.join(
process.cwd(),
`./.cache/babelState.json`
))
} catch (err) {
if (err.message.includes(`Cannot find module`)) {
// This probably is being used outside of the Gatsby CLI.
throw Error(
`\`babel-preset-gatsby\` has been loaded, which consumes config generated by the Gatsby CLI. Set \`NODE_ENV=test\` to bypass, or run \`gatsby build\` first.`
)
} else {
throw err
}
}
}
return pluginBabelConfig
}
Expand Down

0 comments on commit adf06e5

Please sign in to comment.