Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

404.html folder causes EISDIR illegal operations, stops onPostBuild #2

Open
roxberry opened this issue Jul 5, 2021 · 0 comments
Open

Comments

@roxberry
Copy link

roxberry commented Jul 5, 2021

On build:

ERROR #11321  PLUGIN

"gatsby-plugin-doctype" threw an error while running the onPostBuild lifecycle:

EISDIR: illegal operation on a directory, read

Error: EISDIR: illegal operation on a directory, read

Added code to the plugin, found the cause is the 404.html folder:

public/page-data/404.html

Local hacked it:

const glob = require(`tiny-glob`)
const fs = require(`fs-extra`)

async function getContent(filePath, encoding = 'utf-8') {
  if (!filePath) {
    throw new Error('filePath required or not found')
  }

  if (fs.lstatSync(filePath).isDirectory() ) {
    console.log ('*******************' + filePath + ' is a directory')
    return null
  }
  return fs.readFile(filePath, { encoding })
}

exports.onPostBuild = async (_, { doctype = `html` }) => {
  const files = await glob(`public/**/*.html`)

  for (const file of files) {
    const originalContent = await getContent(file)

    if (originalContent == null)
    {
      continue;
    }

    const stripped = originalContent.slice(15)
    const start = `<!DOCTYPE ${doctype}>`
    const modifiedContent = `${start}${stripped}`

    await fs.writeFile(file, modifiedContent)
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant