Docsite 安裝完成後 查看版本及啓動時的異常處理


前情提要:docsite及npm小白的爬坑之路,大佬莫見笑


先把解決方案給大家,再說說爬坑

1、如果你docsite 安裝完成後執行 docsite命令直接就報錯,請參考:
報錯內容指向docsite內部文件,可聯繫docsite開發進行修復,等他修復完成,你這裏進行

  • npm cache clean --force
  • npm uninstall docsite -g && npm i docsite@** -g

2、docsite 以及 docsite -V命令都正常,而docsite start執行異常,請參考:

  • 執行 docsite start需要在項目根目錄下進行
  • 如果沒有現成的項目,就新建項目目錄,進入項目目錄執行 docsite init, 初始化完成執行docsite start
  • 如果有現成的項目,請直接在項目根目錄下執行docsite start

docsite@**指的是你安裝的docsite項目名。

爬坑之路

1.深夜摸索:

由於第一天是晚上快十一點纔開始着手閱讀readme 安裝docsite,新電腦沒有node和npm那些,加上前端不是很熟,就折騰的多了些。折騰完docsite安裝完成,心想只要執行下一步的啓動 docsite start終於可以看到正兒八經的docsite頁面了。

這個時候,報錯來了:

$ docsite
D:\nvm\v8.16.0\node_modules\docsite\lib\generateJSONFile.js:26
  langList = [{
  ^

TypeError: Cannot destructure property `langList` of 'undefined' or 'null'.
    at Object.<anonymous> (D:\nvm\v8.16.0\node_modules\docsite\lib/generateJSONFile.js:26:5)
    at Module._compile (module.js:653:30)
    at Module._compile (D:\nvm\v8.16.0\node_modules\docsite\node_modules\pirates\lib\index.js:99:24)
    at Module._extensions..js (module.js:664:10)
    at Object.newLoader [as .js] (D:\nvm\v8.16.0\node_modules\docsite\node_modul                              es\pirates\lib\index.js:104:7)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)

心想,什麼錯沒見過,仔細看了下readme,下面有講,可能是node版本太高的問題:

READEME.md 的 Build instruction 部分 :

Build instruction
1.Run npm i docsite@wuhan2020 -g to install docsite for project wuhan2020.
2.Run npm i in the root directory to install the dependencies.
3.Run docsite start in the root directory to start a local server, you will see the website in 'http://127.0.0.1:8080'.
4.Run docsite build to build source code.
Verify your change locally: python -m SimpleHTTPServer 8000, when your python version is 3 use :python3 -m http.server 8000 instead.
If you have higher version of node installed, you may consider nvm to allow different versions of node coexisting on your machine.

Follow the instructions to install nvm
1.Run nvm install v8.16.0 to install node v8
2.Run nvm use v8.16.0 to switch the working environment to node v8
3.Run npm i docsite@wuhan2020 -g to install docsite for project wuhan2020.
Make sure npm and docsite are configured in the environmet configuration of os . eg: /etc/profile or .bash_profile of Macos

Then you are all set to run and build the website. Follow the build instruction above for the details.

然後我就想這個提示很溫暖,感激涕零的就去搞了nvm,把node換成了低版本,重新來一遍。
好,ok,docsite也安裝完成了,這個時候已經深夜一點左右,終於可以睡覺了,完美。輸入 docsite start,瞬間一臉黑線,還是他!!又是他!!!

只好百度谷歌一番,哇,百度竟然沒有遇到這個問題的,就算是替換掉 日誌中的字段名 langList百度的結果也很少,就去了谷歌,依然沒有原錯誤,就找了幾個類似錯誤(字段名不同)看了下,都講的是去找報錯地方的語法。但是呢,這個報錯的地方可是原項目的東西啊,我怎麼可能去改,而且項目issue中也沒看到別人有這個錯誤,我就想一定是自己的錯。谷歌半天,一無所獲,快要兩點了,唉,去原項目提了issue就睡了,第二天工作日啊!雖然是遠程工作!

2.二次折磨

第二天午休間隙【遠程上班雖然可以偷懶,但是確實任務繁重啊,是在抽不開時間搞工作以外的】,說到午間休息,就想起了docsite這貨,趕緊去郵箱看有沒回復我的issue,沒有,我就在本項目docsite也提了issue,前一天是在阿里的原始docsite提的issue。很迷茫···還是沒有辦法,腦瓜子嗡嗡的。繼續認真上班了。。晚上加完班又搞,把所有相關node,nvm,docsite全部卸載完,全部重新來,一頓操作,你們懂的,還是他!!又是他!!!唉,心痛。睡覺

3.驚喜

第三天也就今天-週五,一天上班太緊湊,就壓根沒想起來他,週五是很開心早早下班的,所以意興闌珊的翻起了GitHub,哎?想起他了,也沒看郵箱,就去找issue,發現不見了,就去close的issue去找,發現有人回答了,原項目那個issue也看了,是同一個人回覆的,看樣子是原項目的同學。好的,我來執行他提供的重新安裝docsite的命令。

npm uninstall docsite -g && npm i docsite@wuhan2020 -g

沒錯! 是個驚喜:

npm ERR! Error: EPERM: operation not permitted, mkdir 'D:\nodejs\node_modules\docsite\node_modules'
npm ERR!  { Error: EPERM: operation not permitted, mkdir 'D:\nodejs\node_modules\docsite\node_modules'
npm ERR!   cause:
npm ERR!    { Error: EPERM: operation not permitted, mkdir 'D:\nodejs\node_modules\docsite\node_modules'
npm ERR!      errno: -4048,
npm ERR!      code: 'EPERM',
npm ERR!      syscall: 'mkdir',
npm ERR!      path: 'D:\\nodejs\\node_modules\\docsite\\node_modules' },
npm ERR!   stack: 'Error: EPERM: operation not permitted, mkdir \'D:\\nodejs\\node_modules\\docsite\\node_modules\'',
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: 'D:\\nodejs\\node_modules\\docsite\\node_modules' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2020-02-14T13_35_28_752Z-debug.log
4.幸福又失望

權限問題?清下緩存?

C:\Users\Administrator> npm cache clean --force
npm WARN using --force I sure hope you know what you are doing.

再重新裝下docsite

npm uninstall docsite -g && npm i docsite@wuhan2020 -g

~~焦急而又耐心的等待着
~~
~~
~~
好長一大段,之前根本沒見過
好長一大段,之前根本沒見過,輸入docsite試下:
在這裏插入圖片描述
大場面,真的沒見過,趕緊docsite -h學習一波

C:\Users\Administrator>docsite -h
Usage: docsite <command> [options]

Options:
  -V, --version   output the version number
  init [project]  init project
  start           start a local server
  build           build assets
  -h, --help      output usage information

幸福啊~~~

幸福的是什麼呢? docsite的第一個命令終於不報錯了,還看到到期待的 docsite start 命令的提示 哈哈哈


docsite start 開始你的表演!

C:\Users\Administrator>docsite start
(node:12412) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, scandir 'C:\Users\Administrator\src\pages'
    at Object.fs.readdirSync (fs.js:904:18)
    at generateHTMLFile (D:\nvm\v8.16.0\node_modules\docsite\lib\generateHTMLFile.js:98:20)
    at start (D:\nvm\v8.16.0\node_modules\docsite\lib\start.js:72:3)
    at main (D:\nvm\v8.16.0\node_modules\docsite\bin\docsite.js:29:7)
    at main.next (<anonymous>)
    at onFulfilled (D:\nvm\v8.16.0\node_modules\docsite\node_modules\co\index.js:65:19)
    at D:\nvm\v8.16.0\node_modules\docsite\node_modules\co\index.js:54:5
    at new Promise (<anonymous>)
    at co (D:\nvm\v8.16.0\node_modules\docsite\node_modules\co\index.js:50:10)
    at Object.<anonymous> (D:\nvm\v8.16.0\node_modules\docsite\bin\docsite.js:13:1)
(node:12412) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:12412) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

一盆涼水,從頭上澆了下來,別忽悠我啊,你說可以執行的!
於是去docsite根目錄執行看看,依然。。。

看樣子依然是他項目內部錯誤呀,和第一天遇到的是同一種問題嘛
又屁顛去issue找他去了

5.完美

隔了一天,終於等到了回覆,是我的無知漏掉了一個重要步驟:項目初始化

再次看了一下SaaS後項目的readme指南,發現也是沒有初始化這一步的,就把我帶進了坑裏。在上面的深夜摸索裏邊有他的readme指南,不難發現,他沒有初始化這個字眼的。但是,細節在這裏:

2.Run npm i in the root directory to install the dependencies.
3.Run docsite start in the root directory to start a local server, you will see the website in 'http://127.0.0.1:8080'.

這兩步都有一句 in the root directory, 要去根目錄執行這兩個命令,開始就是對這句理解有問題,我理解的根目錄是去電腦用戶家目錄直接執行,看來太年輕,這裏竟然指的是 項目根目錄,那麼我就認爲 這句話補全爲 in the root directory of this project 會更親切一點。

但是,有沒仔細看之前我們輸入 docsite -h的時候命令提示,你上去看下。hiahiahia,扎心 0.0

來,解決問題:

  • 1.我們新建一個項目目錄,cmd cd到該目錄執行 docsite init ,針對已有的項目就不用新建項目目錄啦,在拉下來的項目根目錄下執行 npm i 就可以啦。

注意: docsite init 執行到 類似這樣 added 1334 packages from 885 contributors in 248.309s的字眼是成功了的,只是他自己不結束,需要我們 ctrl + c 一下。

  • 2.項目根目錄下執行 docsite start,you will see the website in ‘http://127.0.0.1:8080’.

總結

	 1.報錯日誌指向哪裏的文件,優先去找那裏的錯誤。
	 2.官方代碼也不一定沒BUG
	 3.官方指南也不一定對
	 4.細節!

可能這個總結不是很到位,歡迎大家斧正,加油!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章