ローカルのNexus3にnpm publishでNodeモジュールをデプロイする
手順
参考[4]の手順に沿って実施すればできます。(英語ですが)
Nexus3のインストール
公式ドキュメントである参考[1]を用いて、Nexus3をローカルにインストールします。
インストール後はcliから起動させます。
nexus-3.16.2-01\bin>nexus.exe /install Installed service 'nexus'. nexus-3.16.2-01\bin>nexus.exe /start Starting service 'nexus'. nexus-3.16.2-01\bin>nexus.exe /status Running. Auto-start.
起動すると http://localhost:8081/ でNexus3にアクセスできるようになります。
Repositoryの作成
npm-privateというリポジトリをGUIから作成しました。
cliでnexusにログイン
npm login --registry=http://localhost:8081/repository/npm-private/
publish
以下のコマンドでローカルリポジトリにpublishできます。その際にpackage.jsonは以下のような記載が必要です。
"publishConfig":{"registry":"http://localhost:8081/repository/npm-private/"}
npm publish
Tips
networkの問題が発生
npm notice npm ERR! publish Failed PUT undefined npm ERR! code ECONNRESET npm ERR! errno ECONNRESET npm ERR! syscall read npm ERR! network read ECONNRESET npm ERR! network This is a problem related to network connectivity. npm ERR! network In most cases you are behind a proxy or have bad network settings. npm ERR! network npm ERR! network If you are behind a proxy, please make sure that the npm ERR! network 'proxy' config is set properly. See: 'npm help config' npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\hoge\AppData\Roaming\npm-cache\_logs\2019-06-10T04_58_47_418Z-debug.log
npm config ls -l
でnpmのconfigを確認するとプロキシが有効になっていることがわかったので、プロキシを無効にした。
> call npm -g config delete proxy > call npm -g config delete https-proxy > call npm -g config delete registry
npm publishした場合に401エラーが発生
npm notice npm ERR! publish Failed PUT 401 npm ERR! code E401 npm ERR! 401 Unauthorized npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\hoge\AppData\Roaming\npm-cache\_logs\2019-06-10T05_05_54_339Z-debug.log
参考[3]を参照することで解決した。つまり npm Bearer Token Realm をActiveにした。
npm publishできない
npm error. This package has been marked as private npm error. Remove the 'private' field from the package.json to publish it.
参考[5]のようにpackage.jsonに private:true
が設定されているとpublishはできないためでした。private:true
を削除してpublishできるようになりました。
参考
- https://help.sonatype.com/repomanager3/installation
- https://github.com/verdaccio/verdaccio/issues/180
- https://stackoverflow.com/questions/39460074/unable-to-publish-to-an-npm-registry-local
- https://levelup.gitconnected.com/deploying-private-npm-packages-to-nexus-a16722cc8166
- https://github.com/verdaccio/verdaccio/issues/180
- https://docs.npmjs.com/misc/registry