vercel / pkg

Package your Node.js project into an executable
https://npmjs.com/pkg
MIT License
24.28k stars 1.01k forks source link

ffi-napi Error: Dynamic Linking Error: Win32 error 126 #1991

Closed Jey0707 closed 8 months ago

Jey0707 commented 11 months ago

What version of pkg are you using?

5.5.1

What version of Node.js are you using?

v16.15.1

What operating system are you using?

Windows

What CPU architecture are you using?

x86_64

What Node versions, OSs and CPU architectures are you building for?

node16-win-x64

Describe the Bug

I'm creating a pkg with a compiled typescript build with an imported .dll file with ffi-napi and I'm getting this error:

Error: Dynamic Linking Error: Win32 error 126 at new DynamicLibrary (C:\snapshot\Amazon Bot\node_modules\ffi-napi\lib\dynamic_library.js:75:11) at Library (C:\snapshot\Amazon Bot\node_modules\ffi-napi\lib\library.js:47:10)

I have checked if the path to the file is correct and yes, it is. This is my package.json

{
  "name": "amazon-monitor",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "bin": "./build/index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "npx nodemon",
    "lint": "eslint . --ext .ts",
    "pkg": "pkg . -d",
    "version":"pkg --vers"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/ffi-napi": "^4.0.7",
    "@types/node": "^20.5.6",
    "@types/node-fetch": "^2.6.4",
    "@typescript-eslint/eslint-plugin": "^6.6.0",
    "@typescript-eslint/parser": "^6.6.0",
    "eslint": "^8.49.0",
    "nodemon": "^3.0.1",
    "ts-node": "^10.9.1",
    "typescript": "^5.2.2"
  },
  "pkg": {
    "assets": [
      "assets/*",
      "node_modules/ffi-napi/**/*",
      "node_modules/ref-napi/**/*"
    ],
    "targets": [
      "node16-win-x64"
    ],
    "outputPath": "dist"
  },
  "dependencies": {
    "cheerio": "^1.0.0-rc.12",
    "discord-webhook-node": "^1.1.8",
    "ffi-napi": "^4.0.3",
    "node-fetch": "^2.7.0",
    "node-machine-id": "^1.1.12"
  }
}

I have also checked and tried the solutions from https://github.com/vercel/pkg/issues/1744 but do not work for me.

I'm calling the .dll in this way:

const clientPath = path.join(__dirname, '..', '..', 'assets', 'client.dll');
    console.log('file exists:', existsSync(clientPath) ? 'yes' : 'no')

    return Library(clientPath, {
        request: ['string', ['string']],
        getCookiesFromSession: ['string', ['string']],
        addCookiesToSession: ['string', ['string']],
        freeMemory: ["void", ['string']],
        destroyAll: ['string', []],
        destroySession: ['string', ['string']]
    });

Expected Behavior

.exe starts without error

To Reproduce

Run npm run pkg and the executable will show this error: Error: Dynamic Linking Error: Win32 error 126 at new DynamicLibrary (C:\snapshot\Amazon Bot\node_modules\ffi-napi\lib\dynamic_library.js:75:11) at Library (C:\snapshot\Amazon Bot\node_modules\ffi-napi\lib\library.js:47:10)

github-actions[bot] commented 8 months ago

This issue is stale because it has been open 90 days with no activity. Remove the stale label or comment or this will be closed in 5 days. To ignore this issue entirely you can add the no-stale label

github-actions[bot] commented 8 months ago

This issue is now closed due to inactivity, you can of course reopen or reference this issue if you see fit.