天天看點

Nodejs Error: Cannot find module 'unicode/category/So'

Error: Cannot find module ‘unicode/category/So’

前幾天用了keystonejs,一個node開發的不錯的CMS架構,在把代碼部署到一台新的阿裡雲機器後,出現了一些問題。

由于npm某些包被GFW牆掉,是以我在阿裡雲使用了cnpm,cnpm安裝如下:

npm install -g cnpm --registry=https://registry.npm.taobao.org
ln -s /usr/local/node/bin/cnpm /usr/local/bin/cnpm #為cnpm建立軟連接配接
           

使用cnpm安裝package.json中的依賴包。日志如下,中間忽略部分module的安裝。

[[email protected]~] installed at node_modules/.npminstall/debug//debug ( packages, use ms, speed kB/s, json kB, tarball kB)
......
[[email protected]^] installed at node_modules/.npminstall/keystone//keystone ( packages, use s, speed MB/s, json MB, tarball MB)
excute post install scripts...
[spawn-sync@1] scripts.postinstall: "node postinstall" at /root/juyou_server_cms/node_modules/.npminstall/spawn-sync//spawn-sync
[spawn-sync@1] scripts.postinstall success, use ms
[node-sass@3] scripts.install: "node scripts/install.js" at /root/juyou_server_cms/node_modules/.npminstall/node-sass//node-sass
Binary downloaded and installed at /root/juyou_server_cms/node_modules/.npminstall/node-sass//node-sass/vendor/linux-x64-/binding.node
[node-sass@3] scripts.install success, use s
[node-sass@3] scripts.postinstall: "node scripts/build.js" at /root/juyou_server_cms/node_modules/.npminstall/node-sass//node-sass
` /root/juyou_server_cms/node_modules/.npminstall/node-sass//node-sass/vendor/linux-x64-/binding.node ` exists. 
 testing binary.
Binary is fine; exiting.
[node-sass@3] scripts.postinstall success, use ms
[buffertools@2] scripts.install: "node-gyp rebuild" at /root/juyou_server_cms/node_modules/.npminstall/buffertools//buffertools
sh: node-gyp: command not found
[Error: Run "sh -c node-gyp rebuild" error, exit code 
    at ChildProcess.<anonymous> (/usr/local/node/lib/node_modules/cnpm/node_modules/runscript/index.js::)
    at emitTwo (events.js::)
    at ChildProcess.emit (events.js::)
    at maybeClose (internal/child_process.js::)
    at Process.ChildProcess._handle.onexit (internal/child_process.js::)@%s] optional error: %s
All packages installed ( packages installed from npm registry, use s, speed MB/s, json (MB), tarball MB)
           

**[[email protected]] scripts.install: “node-gyp rebuild” at /root/juyou_server_cms/node_modules/.npminstall/buffertools/2.1.3/buffertools

sh: node-gyp: command not found

[Error: Run “sh -c node-gyp rebuild” error, exit code 127**

悲劇是從這裡開始的。buffertools工具需要node-gyp rebuild,但是我環境裡并沒有安裝node-gyp

啟動node keystone.js後開始報錯

如下

module.js:341
    throw err;
    ^

Error: Cannot find module 'unicode/category/So'
    at Function.Module._resolveFilename (module.js:339:15)
    at Function.Module._load (module.js:290:25)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
           

缺少unicode/category/So,我以為缺少unicode包,繼續用cnpm install unicode來安裝。結果提示

[unicode@*] existed at node_modules/.npminstall/unicode//unicode ( packages, use ms, speed kB/s, json kB, tarball B)
All packages installed (use ms, speed kB/s, json (kB), tarball B)
           

但是進入node_module/unicode後發現裡面并沒有So等檔案

使用npm install unicode安裝

提示

npm WARN skippingAction Module is inside a symlinked module: not running remove babel-runtime@ node_modules/keystone/node_modules/babel-core/node_modules/babel-template/node_modules/babel-runtime
.......
           

因為node_modules/.npminstall裡已經有了unicode的軟連接配接。

使用cnpm unistall unicode,結果提示如下

- [email protected] node_modules/unicode
npm WARN enoent ENOENT: no such file or directory, open '/root/juyou_server_cms/node_modules/.npminstall/unicode/0.6.1/unicode/category/package.json'
npm WARN category No description
npm WARN category No repository field.
npm WARN category No README data
npm WARN category No license field.
           

因為沒有被正确的安裝,是以也沒法解除安裝。

  1. 手動删除了node_modules下的unicode,并删除了.npminstall下的所有軟連結。
  2. cnpm install -g node-gyp,安裝node-gyp
  3. cnpm install unicode,重新安裝unicode子產品

這次終于成功的安裝了unicode子產品,使用nohup node keystone.js &後順利的啟動了keystone.js