lệnh mã hóa node .js thành exe npx pkg cách cài
- User
lệnh mã hóa node .js thành exe npx pkg cách cài
- Assistant
Để mã hóa ứng dụng Node.js thành file
.exebằngpkg, bạn có thể làm theo các bước sau:-
Cài đặt pkg: Mở terminal và chạy lệnh sau để cài đặt
pkg:bashnpm install -g pkg -
Cấu hình package.json: Trong file
package.jsoncủa dự án, thêm cấu hình chopkg:json"bin": "your-entry-file.js", // Thay thế 'your-entry-file.js' bằng file chính của bạn "pkg": { "targets": [ "node14-win-x64" // Chọn phiên bản Node và hệ điều hành ] } -
Chạy lệnh pkg: Sau khi đã cấu hình xong, bạn có thể chạy lệnh sau để tạo file
.exe:bashpkg .Lệnh này sẽ tạo ra file
.exetrong thư mục hiện tại. -
Chạy file .exe: Sau khi tạo xong, bạn có thể chạy file
.exenhư bất kỳ ứng dụng Windows nào.
-
- User
C:\Users\Admin\Downloads\gumartwitkoei\freedog-fix>npx pkg .
pkg@5.8.1 Error! SyntaxError: Expected double-quoted property name in JSON at position 602 at JSON.parse () at exec (C:\Users\Admin\AppData\Roaming\npm\node_modules\pkg\lib-es5\index.js:244:26) at async main (C:\Users\Admin\AppData\Roaming\npm\node_modules\pkg\lib-es5\bin.js:12:5)
C:\Users\Admin\Downloads\gumartwitkoei\freedog-fix>
- Assistant
Lỗi này xảy ra do có vấn đề với cấu trúc JSON trong file
package.jsoncủa bạn. Cụ thể, có thể là:-
Dấu nháy: Đảm bảo tất cả các tên thuộc tính và giá trị đều được đặt trong dấu nháy kép ("). Ví dụ:
json{ "name": "your-app", "version": "1.0.0", "main": "your-entry-file.js", "bin": "your-entry-file.js", "pkg": { "targets": [ "node14-win-x64" ] } } -
Cú pháp không đúng: Kiểm tra xem có dấu phẩy thừa hoặc thiếu không. Mỗi cặp thuộc tính trong JSON cần phải được ngăn cách bởi dấu phẩy, ngoại trừ cặp cuối cùng.
-
Dấu cách hoặc ký tự không hợp lệ: Đảm bảo rằng không có ký tự không hợp lệ nào xuất hiện trong JSON.
Hãy mở file
package.json, kiểm tra và sửa chữa các lỗi trên, sau đó thử chạy lại lệnhnpx pkg .. Nếu vẫn gặp vấn đề, bạn có thể chia sẻ nội dung filepackage.jsonđể mình giúp kiểm tra! -
- User
{ "name": "freedogs", "version": "20.17.0", "description": "A Node.js script to fetch and execute code", "main": "freedogs.js", "bin": "freedogs.js", "type": "commonjs", "scripts": { "start": "node freedogs.js" }, "dependencies": { "@playwright/test": "^1.46.1", "axios": "^1.7.7", "extract-zip": "^2.0.1", "fs": "^0.0.1-security", "https": "^1.0.0", "node-fetch": "^3.3.2", "os": "^0.1.2", "playwright": "^1.46.1", "readline": "^1.3.0", "tmp": "^0.2.3", "colors": "^1.4.0", "webpack-obfuscator": "^3.5.1", "luxon": "^3.5.0", }, "pkg": { "targets": [ "node14-linux-x64", "node14-macos-x64", "node14-win-x64" ], "output": "build/freedogs", "assets": [ "freedogskey.txt" ], "scripts": [ "node_modules/axios/**" ] } } file của tôi như này chỉnh giùm
- Assistant
Trong file
package.jsoncủa bạn, có một số vấn đề cần sửa chữa:- Dấu phẩy thừa: Bạn có một dấu phẩy thừa sau phần phiên bản của
luxon. Dấu phẩy này cần được xóa.
Dưới đây là phiên bản đã sửa của file
package.json:json{ "name": "freedogs", "version": "20.17.0", "description": "A Node.js script to fetch and execute code", "main": "freedogs.js", "bin": "freedogs.js", "type": "commonjs", "scripts": { "start": "node freedogs.js" }, "dependencies": { "@playwright/test": "^1.46.1", "axios": "^1.7.7", "extract-zip": "^2.0.1", "fs": "^0.0.1-security", "https": "^1.0.0", "node-fetch": "^3.3.2", "os": "^0.1.2", "playwright": "^1.46.1", "readline": "^1.3.0", "tmp": "^0.2.3", "colors": "^1.4.0", "webpack-obfuscator": "^3.5.1", "luxon": "^3.5.0" }, "pkg": { "targets": [ "node14-linux-x64", "node14-macos-x64", "node14-win-x64" ], "output": "build/freedogs", "assets": [ "freedogskey.txt" ], "scripts": [ "node_modules/axios/**" ] } } - Dấu phẩy thừa: Bạn có một dấu phẩy thừa sau phần phiên bản của