Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lmdb no native build was found with node-gyp-build-optional-packages and linux platform #312

Open
NiekZndt opened this issue Nov 12, 2024 · 5 comments

Comments

@NiekZndt
Copy link

Hello there! I am using Angular together with Nx, PNPM and node18.20.4. I am trying to migrate to the latest version of Angular (18.2.11), which has a dependency on lmbd. I want to build and install my packages for a linux platform with x64 architecture. When installing packages with the command

pnpm install --config.platform=linux --config.architecture=x64

The installation works fine but I run into issues in the postinstall script where the following exception is thrown:

node_modules/.pnpm/[email protected]/node_modules/lmdb: Running install script, failed in 201ms
.../.pnpm/[email protected]/node_modules/lmdb install$ node-gyp-build-optional-packages
│ C:\Users\niekz\WebstormProjects\Angular-frontend\node_modules\.pnpm\[email protected]\node_modules\node-gyp-build-optional-packages\node-gyp-build.js:85
│   throw new Error(errMessage)
│   ^
│ Error: No native build was found for platform=linux arch=x64 runtime=node abi=108 uv=1 libc=glibc node=18.20.4
│     attempted loading from: C:\Users\niekz\WebstormProjects\Angular-frontend\node_modules\.pnpm\[email protected]\node_modules\lmdb and package: @lmdb/lmdb-linux-x64
│ Error resolving package: Cannot find module '@lmdb/lmdb-linux-x64'
│ Require stack:
│ - C:\Users\niekz\WebstormProjects\Angular-frontend\node_modules\.pnpm\[email protected]\node_modules\lmdb\package.json
│     at load.resolve.load.path (C:\Users\niekz\WebstormProjects\Angular-frontend\node_modules\.pnpm\[email protected]\node_modules\node-gyp-build-optional-packages\node-gyp-build.js:85:9)
│     at load (C:\Users\niekz\WebstormProjects\Angular-frontend\node_modules\.pnpm\[email protected]\node_modules\node-gyp-build-optional-packages\node-gyp-build.js:28:30)
│     at Object.<anonymous> (C:\Users\niekz\WebstormProjects\Angular-frontend\node_modules\.pnpm\[email protected]\node_modules\node-gyp-build-optional-packages\build-test.js:19:19)
│     at Module._compile (node:internal/modules/cjs/loader:1364:14)
│     at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
│     at Module.load (node:internal/modules/cjs/loader:1203:32)
│     at Module._load (node:internal/modules/cjs/loader:1019:12)
│     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12)
│     at node:internal/main/run_main_module:28:49
│ Node.js v18.20.4
│ The failure above indicates the primary issue with the native builds which are included for all major platforms. Will now attempt to build the package locally in case this can be resolved by re-compiling.
│ 'C:\Program' is not recognized as an internal or external command,
│ operable program or batch file.
└─ Failed in 201ms at C:\Users\niekz\WebstormProjects\Angular-frontend\node_modules\.pnpm\[email protected]\node_modules\lmdb
 ELIFECYCLE  Command failed with exit code 1.

The package @lmdb/lmdb-linux-x64 is listed under optionalDepencies but in this case should clearly be installed. I am aware that I can resolve this issue by installing the packages using the --force option, however I prefer to not install all packages forcibly on my build server. Is this a problem with lmdb and how can I resolve this?

@NiekZndt
Copy link
Author

Here is my package.json

{
  "name": "angular-frontend",
  "version": "0.0.0",
  "scripts": {
 //...
  },
  "engines": {
    "node": "18.*"
  },
  "private": true,
  "dependencies": {
    "@angular-devkit/build-angular": "18.2.9",
    "@angular-material-components/datetime-picker": "^8.0.0",
    "@angular/animations": "18.2.11",
    "@angular/cdk": "18.2.12",
    "@angular/common": "18.2.11",
    "@angular/compiler": "18.2.11",
    "@angular/core": "18.2.11",
    "@angular/forms": "18.2.11",
    "@angular/localize": "18.2.11",
    "@angular/material": "18.2.12",
    "@angular/platform-browser": "18.2.11",
    "@angular/platform-browser-dynamic": "18.2.11",
    "@angular/router": "18.2.11",
    "@ngrx/component-store": "18.0.2",
    "@ngrx/effects": "18.0.2",
    "@ngrx/operators": "^18.0.0",
    "@ngrx/store": "18.0.2",
    "@ngrx/store-devtools": "18.0.2",
    "@ngx-translate/core": "14.0.0",
    "@ngx-translate/http-loader": "6.0.0",
    "@nx/angular": "20.0.5",
    "@types/canvas-confetti": "1.4.2",
    "@types/html-pdf": "^3.0.3",
    "angularx-qrcode": "15.0.0",
    "canvas-confetti": "1.5.1",
    "codelyzer": "^0.0.28",
    "country-flag-icons": "1.4.0",
    "echarts": "^5.4.3",
    "fs": "^0.0.1-security",
    "html-duration-picker": "^2.4.0",
    "html-pdf": "^3.0.1",
    "html-to-image": "^1.11.11",
    "html2canvas": "^1.4.1",
    "html2pdf.js": "^0.10.1",
    "ibantools": "^4.3.3",
    "jsbarcode": "^3.11.6",
    "json-bigint": "^1.0.0",
    "jspdf": "^2.5.1",
    "jspdf-autotable": "^3.6.0",
    "jwt-decode": "3.1.2",
    "markdown-pdf": "^11.0.0",
    "marked": "^4.3.0",
    "masonry-layout": "4.2.2",
    "material-icons": "1.10.6",
    "ng-mocks": "14.13.1",
    "ng2-pdf-viewer": "^9.1.5",
    "ngx-barcode6": "1.0.20",
    "ngx-device-detector": "4.0.1",
    "ngx-echarts": "^14.0.0",
    "ngx-editor": "15.3.0",
    "ngx-iban": "14.0.0",
    "ngx-markdown": "^14.0.1",
    "ngx-masonry": "13.0.0",
    "node-html-markdown": "1.1.3",
    "nth-check": "^2.1.1",
    "pnpm": "9.12.3",
    "print-js": "^1.6.0",
    "proxy": "^1.0.2",
    "rxjs": "7.8.1",
    "tslib": "^2.3.0",
    "xlsx": "^0.18.5",
    "xlsx-js-style": "^1.2.0",
    "zone.js": "0.14.10"
  },
  "devDependencies": {
    "@angular-devkit/core": "18.2.9",
    "@angular-devkit/schematics": "18.2.9",
    "@angular-eslint/eslint-plugin": "18.0.1",
    "@angular-eslint/eslint-plugin-template": "18.0.1",
    "@angular-eslint/template-parser": "18.0.1",
    "@angular/cli": "~18.2.0",
    "@angular/compiler-cli": "18.2.11",
    "@angular/language-service": "18.2.11",
    "@ngrx/schematics": "18.0.2",
    "@nx/angular": "19.8.10",
    "@nx/eslint": "19.8.9",
    "@nx/eslint-plugin": "19.8.9",
    "@nx/jest": "19.8.9",
    "@nx/js": "19.8.9",
    "@nx/workspace": "19.8.9",
    "@schematics/angular": "18.2.9",
    "@swc-node/register": "1.9.2",
    "@swc/core": "1.5.7",
    "@types/babel__core": "^7.20.1",
    "@types/babel__traverse": "^7.20.0",
    "@types/country-flag-icons": "1.2.0",
    "@types/dom-to-image": "^2.6.4",
    "@types/jest": "29.5.14",
    "@types/json-bigint": "^1.0.4",
    "@types/lodash": "4.14.178",
    "@types/marked": "4.0.3",
    "@types/masonry-layout": "4.2.4",
    "@types/node": "^18.16.9",
    "@typescript-eslint/eslint-plugin": "7.16.0",
    "@typescript-eslint/parser": "7.16.0",
    "@typescript-eslint/utils": "^7.16.0",
    "cypress": "^13.6.0",
    "eslint": "8.57.1",
    "eslint-config-prettier": "9.0.0",
    "eslint-plugin-import": "2.26.0",
    "eslint-plugin-jsdoc": "46.9.0",
    "eslint-plugin-prefer-arrow": "1.2.2",
    "glob": "8.0.3",
    "jest": "29.7.0",
    "jest-circus": "^29.6.1",
    "jest-environment-jsdom": "29.7.0",
    "jest-preset-angular": "14.1.1",
    "json-concat": "0.0.1",
    "jsonc-eslint-parser": "^2.1.0",
    "local-cors-proxy": "^1.1.0",
    "ng-mocks": "^14.11.0",
    "nx": "19.8.9",
    "prettier": "^2.6.2",
    "protractor": "^7.0.0",
    "ts-jest": "29.1.5",
    "ts-node": "10.9.1",
    "typescript": "5.5.4",
    "webpack": "5.96.1",
    "webpack-cli": "4.9.2"
  },
  "pnpm": {
    "overrides": {
      "prosemirror-model": "^1.18.1"
    }
  }
}

@kriszyp
Copy link
Owner

kriszyp commented Nov 12, 2024

The use of optional dependencies is how the right binary package gets installed. lmdb-js lists all the binary packages as optional dependencies, and then package manager installs the one that matches the machine's "os" and "cpu" as listed in the package.json. So here, you are trying to tell pnpm to install a different os/cpu than the installing machine's? Does that really cause pnpm to match on a different os/cpu (AFAICT, those args don't really do that)? FWIW, lmdb-js does include a package.json bin script download-lmdb-prebuilds to download all the binaries.

@NiekZndt
Copy link
Author

Yes my machine itself (and the build server) run on Windows. I found this thread on pnpm about the possibility of cross platform installations: pnpm/pnpm#5965 and this merged request pnpm/pnpm#5965. So it seems like it should be possible. Besides when I run it without the flags the installation performs just fine so I wonder what the flags would be used for otherwise. The error also shows that node-gyp-build-optional-packages tries to find the build for a linux platform. Looking at the source code it shows that they get the platform from the config.

// \node_modules\.pnpm\[email protected]\node_modules\node-gyp-build-optional-packages\node-gyp-build.js:19
var platform = process.env.npm_config_platform || os.platform()

Is this a node-gyp issue then?

@kriszyp
Copy link
Owner

kriszyp commented Nov 12, 2024

Does pnpm set these env variables/config?

@NiekZndt
Copy link
Author

Adding the flag is the same as setting them in your npmrc file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants