Tag Archives: gitbook serve

How to Avoid Windows Error in Gitbook Serve

In Windows environment

$ gitbook serve

If you edit the markdown after execution

Error: EPERM: operation not permitted, lstat [_book directory name]

This is an urgent measure when the gitbook terminates abnormally with the error.

After starting gitbook serve, once you delete the “_book” folder, for some
reason it works normally after that,

[node.js global installation path] /bin/node_modules/gitbook-cli/bin/gitbook.js

If you add a description to delete the “_book” folder, for example, around the 180th to 194th lines of, gitbook servewill not end abnormally.

  • If you are using bash (git bash, etc.) for your shell
program
    .command('*')
    .description('run a command with a specific gitbook version')
    .action(function(commandName){
        var args = parsedArgv._.slice(1);
        var kwargs = _.omit(parsedArgv, '$0', '_');
        runPromise(
            manager.ensureAndLoad(bookRoot, program.gitbook)
            .then(function(gitbook) {
                if(commandName === 'serve'){
                    setTimeout(function(){
                        require('child_process').execSync('rm -rf _book');
                    },1000);
                }
                return commands.exec(gitbook.commands, commandName, args, kwargs);
            })
        );
    });
  • If you are using PowerShell as the shell, make the delete command part as follows
require('child_process').execSync('rm _book -Recurse');

(If you don’t want to make it dependent on the shell, you can delete it with fs.unlink, fs.rmdir, etc.)