GitbookIO / gitbook-cli

GitBook's command line interface

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gitbook serve throws Cannot find module 'internal/util/types' error

JerryChin opened this issue · comments

Problem

Unable to run gitbook serve, the following error is reported:

Error loading version latest: Error: Cannot find module 'internal/util/types'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
    at Function.Module._load (internal/modules/cjs/loader.js:506:25)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at evalmachine.<anonymous>:44:31
    at Object.<anonymous> (C:\Users\Administrator.SKY-20170327BBW\.gitbook\versions\2.5.2\node_modules\npm\node_modules\graceful-fs\fs.js:11:1)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)

TypeError: Cannot read property 'commands' of null

Solving

  • Upgrading Node.js from 8 to 10 is not working.

  • I managed to install a latest version of graceful-fs (4.1.15) , replace the old version(3.0.5) under .gitbook\versions\2.5.2\npm\node_modules\ with it, it works!

Thoughts

though I am not much familiar with Node.js , but suspect the required version of graceful-fs is too old to be compatible with latest node.js npm, maybe do an upgrading?

ENV

node -v
v10.14.1

npm -v
6.4.1

gitbook -V
CLI version: 2.3.2
GitBook version: 2.5.2

Can confirm, I have the same issue, installed via npm and yarn, same result

Error loading version latest: Error: Cannot find module 'internal/util/types'
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at evalmachine.<anonymous>:31:26
    at Object.<anonymous> (/home/patrick/.gitbook/versions/2.6.9/node_modules/graceful-fs/fs.js:11:1)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)

TypeError: Cannot read property 'commands' of null

versions

$ node -v
v8.16.1

$ npm -v
6.4.1

$ gitbook -V
CLI version: 2.3.2
GitBook version: 2.6.9

I updated graceful-fs in gitbook itself, this seems to fix it

cd ~/.gitbook/versions/2.6.9/
nano package.json # see below
yarn # to install new version
{
  "name": "gitbook",
  "version": "2.6.9",
  "homepage": "https://www.gitbook.com",
  "description": "Library and cmd utility to generate GitBooks",
  "main": "lib/index.js",
  "dependencies": {
    "q": "1.0.1",
    "lodash": "3.10.1",
    "graceful-fs": "4.2.2",
    ...
}

I updated npm to the stable version and reinstalled gitbook and it worked
npm cache clean -f
npm install n stable -g
npm cache clean -f
rm -rf ~/.gitbook/*
npm install gitbook-cli -g
gitbook init

I updated npm to the stable version and reinstalled gitbook and it worked
npm cache clean -f
npm install n stable -g
npm cache clean -f
rm -rf ~/.gitbook/*
npm install gitbook-cli -g
gitbook init

I faced the same problem in 05/2021 and these steps worked for me

up up

I updated npm to the stable version and reinstalled gitbook and it worked
npm cache clean -f
npm install n stable -g
npm cache clean -f
rm -rf ~/.gitbook/*
npm install gitbook-cli -g
gitbook init

I faced the same problem in 07/2021 and these steps worked for me

up up 2

I faced the same problem in 03/2022 and these steps worked for me

commented

gitbook init

Works like a charm