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

Closed
NiekZndt opened this issue Nov 12, 2024 · 14 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.

@darora8147
Copy link

Hi, I am also facing the same while trying to migrate to Angular 18v and i have node version as v18.20.4 and npm version as 10.7.0 on my window machine , while trying to publish package on team-dev server via jenkins, install step getting failed with below error

npm error: Error: No native build was found for platform=linux arch=x64 runtime=node abi=108 uv=1 libc=glibc node=18.20.4

Error resolving package: Cannot find module '@lmdb/lmdb-linux-x64'

Is this issue fixed? If yes, please assist with the solution for the same

@NiekZndt
Copy link
Author

Hey there, unfortunately I was unable to resolve this issue. We are planning on containerizing our building process so that we can build it inside of a linux environment (in my case I was building on windows for linux).

@mateher624
Copy link

mateher624 commented Feb 4, 2025

@darora8147, @NiekZndt if your issue is still relevant, I found solution to this.

Just added other variants of darwin/linux/win32 and arm/arm64/x64 as dependency to my package-lock.json and the problem was gone. I noticed this code is generated in package-lock.json if you reference lmdb explicitly.

Also upgrading Angular to 19.x helps since lmdb is optional package there.

Here are deps you can copy and paste:

        "node_modules/@angular/build/node_modules/@lmdb/lmdb-darwin-arm64": {
            "version": "3.0.13",
            "resolved": "https://registry.npmjs.org/@lmdb/lmdb-darwin-arm64/-/lmdb-darwin-arm64-3.0.13.tgz",
            "integrity": "sha512-uiKPB0Fv6WEEOZjruu9a6wnW/8jrjzlZbxXscMB8kuCJ1k6kHpcBnuvaAWcqhbI7rqX5GKziwWEdD+wi2gNLfA==",
            "cpu": [
                "arm64"
            ],
            "dev": true,
            "license": "MIT",
            "optional": true,
            "os": [
                "darwin"
            ]
        },
        "node_modules/@angular/build/node_modules/@lmdb/lmdb-darwin-x64": {
            "version": "3.0.13",
            "resolved": "https://registry.npmjs.org/@lmdb/lmdb-darwin-x64/-/lmdb-darwin-x64-3.0.13.tgz",
            "integrity": "sha512-bEVIIfK5mSQoG1R19qA+fJOvCB+0wVGGnXHT3smchBVahYBdlPn2OsZZKzlHWfb1E+PhLBmYfqB5zQXFP7hJig==",
            "cpu": [
                "x64"
            ],
            "dev": true,
            "license": "MIT",
            "optional": true,
            "os": [
                "darwin"
            ]
        },
        "node_modules/@angular/build/node_modules/@lmdb/lmdb-linux-arm": {
            "version": "3.0.13",
            "resolved": "https://registry.npmjs.org/@lmdb/lmdb-linux-arm/-/lmdb-linux-arm-3.0.13.tgz",
            "integrity": "sha512-Yml1KlMzOnXj/tnW7yX8U78iAzTk39aILYvCPbqeewAq1kSzl+w59k/fiVkTBfvDi/oW/5YRxL+Fq+Y1Fr1r2Q==",
            "cpu": [
                "arm"
            ],
            "dev": true,
            "license": "MIT",
            "optional": true,
            "os": [
                "linux"
            ]
        },
        "node_modules/@angular/build/node_modules/@lmdb/lmdb-linux-arm64": {
            "version": "3.0.13",
            "resolved": "https://registry.npmjs.org/@lmdb/lmdb-linux-arm64/-/lmdb-linux-arm64-3.0.13.tgz",
            "integrity": "sha512-afbVrsMgZ9dUTNUchFpj5VkmJRxvht/u335jUJ7o23YTbNbnpmXif3VKQGCtnjSh+CZaqm6N3CPG8KO3zwyZ1Q==",
            "cpu": [
                "arm64"
            ],
            "dev": true,
            "license": "MIT",
            "optional": true,
            "os": [
                "linux"
            ]
        },
        "node_modules/@angular/build/node_modules/@lmdb/lmdb-linux-x64": {
            "version": "3.0.13",
            "resolved": "https://registry.npmjs.org/@lmdb/lmdb-linux-x64/-/lmdb-linux-x64-3.0.13.tgz",
            "integrity": "sha512-vOtxu0xC0SLdQ2WRXg8Qgd8T32ak4SPqk5zjItRszrJk2BdeXqfGxBJbP7o4aOvSPSmSSv46Lr1EP4HXU8v7Kg==",
            "cpu": [
                "x64"
            ],
            "dev": true,
            "license": "MIT",
            "optional": true,
            "os": [
                "linux"
            ]
        },
        "node_modules/@angular/build/node_modules/@lmdb/lmdb-win32-x64": {
            "version": "3.0.13",
            "resolved": "https://registry.npmjs.org/@lmdb/lmdb-win32-x64/-/lmdb-win32-x64-3.0.13.tgz",
            "integrity": "sha512-UCrMJQY/gJnOl3XgbWRZZUvGGBuKy6i0YNSptgMzHBjs+QYDYR1Mt/RLTOPy4fzzves65O1EDmlL//OzEqoLlA==",
            "cpu": [
                "x64"
            ],
            "dev": true,
            "license": "MIT",
            "optional": true,
            "os": [
                "win32"
            ]
        },

@NiekZndt
Copy link
Author

NiekZndt commented Feb 5, 2025

Ah thank you so much. At the time Angular 19 was not released yet so we ended up containerizing our build server which was the way to go anyways. Thanks regardless!

@NiekZndt NiekZndt closed this as completed Feb 5, 2025
@darora8147
Copy link

Hi@mateher624 I have tried the solution suggested by you regarding adding of other variants of darwin/linux/win32 and arm/arm64/x64 as dependency to my package-lock.json, but no luck.

I am still getting the same below error.

npm error: Error: No native build was found for platform=linux arch=x64 runtime=node abi=108 uv=1 libc=glibc node=18.20.4

Error resolving package: Cannot find module '@lmdb/lmdb-linux-x64'

Please assist

@rogerwalt
Copy link

We currently have the same issue on a CI node, it works on our MacBooks with Apple silicon chips. Weirdly it works in other builds on the same CI nodes and there is no big difference in either package.json or package-lock.json.

@rogerwalt
Copy link

@darora8147 we were able to fix the issue. We carefully rebuilt package-lock.json (don't forget to remove the node_modules folder and package-lock.json). Now the different binary variants of lmdb, especially the one that was missing for us on CI ("node_modules/@angular/build/node_modules/@lmdb/lmdb-linux-x64") shows up again in package-lock.json. I don't know which configuration (npm version, configuration, ...) led to the wrong package-lock.json file.

@NiekZndt
Copy link
Author

@rogerwalt Could it be that your package-lock is included in your version control? Perhaps someone pushed a package-lock version for a different system to remote.

@rogerwalt
Copy link

Yes definitely. We couldn't figure out how package-lock.json ended up in a broken state. Every time we regenerate it now on Apple Silicon Macs, it's correct and works just fine on the linux-x64 pipeline 😎. We always use npm ci and check in package-lock.json to version control.

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

5 participants