2017-04-21 68 views
1

我想大NPM包發佈到一個私人的Nexus 3 NMP資源庫,但操作失敗,出現以下錯誤出版大NPM包

npm ERR! node v7.7.4 
npm ERR! npm v4.1.2 

npm ERR! "toString()" failed 
npm ERR! 
npm ERR! If you need help, you may report this error at: 
npm ERR!  <https://github.com/npm/npm/issues> 

的問題是在V8的水平和建設時,會出現請求向Nexus發佈。

發佈大型npm包不是一個好的做法,但它是第三方插件,我們需要它用於該項目。

有沒有辦法配置/修補V8以支持更大的文件大小?

將npm包上傳到nexus的請求格式是什麼,所以我可以嘗試使用其他工具將包轉換爲編碼字符串?

+0

「大」有多大?我們在談論什麼文件大小?你能詳細瞭解爲什麼「toString()」失敗嗎?你確定這是你遇到的尺寸限制嗎? – jmrk

+0

是的,它很大。它差不多是1GB。有關於這個問題的一些帖子,這裏是其中之一https://github.com/npm/npm/issues/9552。但我找不到解決方案。 – Nenad

回答

1

我用CURL發佈了這個包。請求的格式是

curl -H "Content-Type: application/json"\ 
-H "Authorization: Basic ${authorization_token}"\ 
-H "Content-Length: ${actual size of the request body in bytes (just check the size of the request body file)}"\ 
-H "Accept-Encoding: gzip"\ 
-H "version: 8.1.1"\ 
-H "Accept: application/json"\ 
-H "npm-session: a972cb330cbacab5"\ 
-H "npm-in-ci: false"\ 
-H "User-Agent: node/v7.7.4"\ 
-H "Host: nexus.example.com:8081"\ 
-X PUT\ 
--data-binary @path_to_request_body_file\ 
--verbose\ 
http://nexus.example.com:8081/nexus/repository/npmrepo/ExamplePackage 

nexus.example.com:8081 - 是實際的關係服務器主機和端口
authorization_token - 是關係授權令牌
npmrepo - 通過的Nexus庫創建的NPM庫經理,其中ExamplePackage將發佈
path_to_request_body_file - 應該是文件路徑與內容的格式請求體文件如下

{ 
    "_id": "ExamplePlugin", 
    "name": "ExamplePlugin", 
    "description": "Example Plugin", 
    "dist-tags": { 
    "latest": "0.1.0" 
    }, 
    "versions": { 
    "0.1.0": { 
     "name": "ExamplePlugin", 
     "version": "0.1.0", 
     "cordova_name": "ExamplePlugin", 
     "description": "Example Plugin", 
     "license": "Apache 2.0", 
     "keywords": [ 
     "ExamplePlugin", 
     "StackoverflowExample" 
     ], 
     "platforms": [ 
     "ios", 
     "android" 
     ], 
     "engines": [], 
     "dependencies": {}, 
     "maintainers": [ 
     { 
      "name": "example_nexus_user", 
      "email": "[email protected]" 
     } 
     ], 
     "_id": "[email protected]", 
     "dist": { 
     "shasum": "${shasum of the package archive file}", 
     "tarball": "http://nexus.example.com:8081/nexus/repository/npmrepo/ExamplePlugin/-/ExamplePlugin-0.1.0.tgz" 
    } 
    } 
    }, 
    "readme": "", 
    "access": "public", 
    "maintainers": [ 
    { 
     "name": "example_nexus_user", 
     "email": "[email protected]" 
    } 
    ], 
    "_attachments": { 
    "ExamplePlugin-0.1.0.tgz": { 
     "content_type": "application/octet-stream", 
     "data": "${Base64 encoded content of the npm package archive}", 
     "length": "${actual size of the package archive in bytes}" 
    } 
    } 
} 

如果包檔案文件d不存在,您可以使用npm pack來生成它。
我已使用openssl爲包檔案openssl base64 -in ExamplePlugin-0.1.0.tgz -out ExamplePluginEncoded生成base64編碼字符串,但可以使用任何其他支持大文件的工具。
我已經使用shasum -a 1 ExamplePlugin-0.1.0.tgz生成了包歸檔的shasum,也可以使用其他一些工具。

我得到了請求的格式和調試npm-registry-client的JSON有效載荷,其中一些字段可能不是必需的,也可能有更多的選項可用。