nodejs 実行可能ファイルを pkg でパッケージ化するにはどうすればよいですか?次の記事では、pkg を使用して Node プロジェクトを実行可能ファイルにパッケージ化する方法を紹介します。
##Node.js
##Node.js
プロジェクトを実行可能ファイルとしてパッケージ化でき、Node.js がインストールされていないデバイスでも実行できます。
#実験環境オペレーティング システム: Windows ノード バージョン: 16.14.2
操作手順
PKGダウンロード
これをグローバルにインストールし、任意のディレクトリで実行することを選択できます。$ npm install -g pkg
パッケージング プログラム
簡単なプログラムを作成します。最初にプログラム (server.js コンテンツなど)
const express = require('express'); const app = express(); app.get('/', (req, res) => { res.send('Hello World!'); }); app.listen(3000, () => { console.log('Express web app on localhost:3000'); });
nodejs プロジェクトのルート ディレクトリに移動し、次のコマンドを実行します
$ pkg server.js
最初のエラーが報告されます
# #この時点でエラーが報告されます$ pkg server.js
> pkg@5.6.0
> Targets not specified. Assuming:
node16-linux-x64, node16-macos-x64, node16-win-x64
> Fetching base Node.js binaries to PKG_CACHE_PATH
fetched-v16.14.2-linux-x64 [ ] 0%> Not found in remote cache:
{"tag":"v3.3","name":"node-v16.14.2-linux-x64"}
> Building base binary from source:
built-v16.14.2-linux-x64
> Error! Not able to build for 'linux' here, only for 'win'
$ pkg -t win server.js
$ pkg -t win server.js > pkg@5.6.0 > Fetching base Node.js binaries to PKG_CACHE_PATH fetched-v16.14.2-win-x64 [ ] 0%> Not found in remote cache: {"tag":"v3.3","name":"node-v16.14.2-win-x64"} > Building base binary from source: built-v16.14.2-win-x64 > Fetching Node.js source archive from nodejs.org... > Error! AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:
{"tag":"v3.3","name":"node-v16.14.2-win-x64"}
$ pkg -t win server.js > pkg@5.6.0
以上がpkg を使用して Node.js プロジェクトを実行可能ファイルにパッケージ化するにはどうすればよいですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。