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

Document the supported node version in .nvmrc #745

Closed
wants to merge 1 commit into from

Conversation

PierreFritsch
Copy link
Contributor

I would suggest documenting the expected node version programmatically.

The README states:

Ensure you have the latest LTS version of Node.js installed

Currently, the latest LTS version of Node.js seems to be Node.js 20.

However, when I clone this repo, and I nvm use the node version 20.16.0, and I npm install and I start the app with npm run fiori, then I get the error:

❗️ ERROR on server start: ❗️

 Error: The module '/Users/me/git/cloud-cap-samples/node_modules/better-sqlite3/build/Release/better_sqlite3.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 108. This version of Node.js requires
NODE_MODULE_VERSION 115. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at Module._extensions..node (node:internal/modules/cjs/loader:1454:18)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Module._load (node:internal/modules/cjs/loader:1024:12)
    at Module.require (node:internal/modules/cjs/loader:1233:19)
    at require (node:internal/modules/helpers:179:18)
    at bindings (/Users/me/git/cloud-cap-samples/node_modules/bindings/bindings.js:112:48)
    at new Database (/Users/me/git/cloud-cap-samples/node_modules/better-sqlite3/lib/database.js:48:64)
    at create (/Users/me/git/cloud-cap-samples/node_modules/@cap-js/sqlite/lib/SQLiteService.js:25:21)
    at Pool._createResource (/Users/me/git/cloud-cap-samples/node_modules/generic-pool/lib/Pool.js:319:42)
    at Pool._dispense (/Users/me/git/cloud-cap-samples/node_modules/generic-pool/lib/Pool.js:237:12)
Active connections:0
 {
  code: 'ERR_DLOPEN_FAILED'
}

I retried with node v18.20.4 and it worked fine. I suggest adding a hint about the expected node version as a .nvmrc file in the repo.

Alternatively, the supported node version could be specified in the engines section of the package.json file.

Version information:

@cap-js/asyncapi: 1.0.2
@cap-js/openapi: 1.0.4
@cap-js/sqlite: 1.7.3
@capire/samples: 2.1.0
@sap/cds: 8.0.4
@sap/cds-compiler: 5.0.6
@sap/cds-dk: 8.0.3
@sap/cds-dk (global): 8.0.3
@sap/cds-fiori: 1.2.7
@sap/cds-foss: 5.0.1
@sap/cds-mtxs: 2.0.3
@sap/eslint-plugin-cds: 3.0.4
Node.js: v20.16.0

I would suggest documenting the expected node version programmatically.

The README states:

> Ensure you have the latest LTS version of Node.js installed

Currently, this [seems](https://nodejs.org/en/about/previous-releases) to be Node.js 20.

However, when I clone this repo, and I [`nvm use`](https://github.com/nvm-sh/nvm) the node version 20.16.0, and I `npm install` and I start the app with `npm run fiori`, then I get the error: 

```
❗️ ERROR on server start: ❗️

 Error: The module '/Users/me/git/cloud-cap-samples/node_modules/better-sqlite3/build/Release/better_sqlite3.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 108. This version of Node.js requires
NODE_MODULE_VERSION 115. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at Module._extensions..node (node:internal/modules/cjs/loader:1454:18)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Module._load (node:internal/modules/cjs/loader:1024:12)
    at Module.require (node:internal/modules/cjs/loader:1233:19)
    at require (node:internal/modules/helpers:179:18)
    at bindings (/Users/me/git/cloud-cap-samples/node_modules/bindings/bindings.js:112:48)
    at new Database (/Users/me/git/cloud-cap-samples/node_modules/better-sqlite3/lib/database.js:48:64)
    at create (/Users/me/git/cloud-cap-samples/node_modules/@cap-js/sqlite/lib/SQLiteService.js:25:21)
    at Pool._createResource (/Users/me/git/cloud-cap-samples/node_modules/generic-pool/lib/Pool.js:319:42)
    at Pool._dispense (/Users/me/git/cloud-cap-samples/node_modules/generic-pool/lib/Pool.js:237:12)
Active connections:0
 {
  code: 'ERR_DLOPEN_FAILED'
}
```

I retried with node v18.20.4 and it worked fine. I'd suggest adding a hint about the expected node version as [a `.nvmrc` file](https://github.com/nvm-sh/nvm?tab=readme-ov-file#nvmrc) in the repo.  

Alternatively, the supported node version could be specified in the [engines](https://docs.npmjs.com/cli/v10/configuring-npm/package-json#engines) section of the package.json file.

### Version information:

```
@cap-js/asyncapi: 1.0.2
@cap-js/openapi: 1.0.4
@cap-js/sqlite: 1.7.3
@capire/samples: 2.1.0
@sap/cds: 8.0.4
@sap/cds-compiler: 5.0.6
@sap/cds-dk: 8.0.3
@sap/cds-dk (global): 8.0.3
@sap/cds-fiori: 1.2.7
@sap/cds-foss: 5.0.1
@sap/cds-mtxs: 2.0.3
@sap/eslint-plugin-cds: 3.0.4
Node.js: v20.16.0
```
@chgeo
Copy link
Member

chgeo commented Jul 29, 2024

I can't reproduce the issue. In fact, I have tested different versions and the repo runs fine w/ Node 18, 20, and 22.

I guess there was some old better-sqlite version in your node_modules that caused the issue.

Alternatively, the supported node version could be specified in the engines section of the package.json file.

We do so with >=18 as current value. Also, there is a check at server startup that checks for this requirement.

@chgeo chgeo closed this Jul 29, 2024
@PierreFritsch
Copy link
Contributor Author

Thanks for the retest @chgeo. Finally npm ci solved the issue for me. I retried to reproduce the issue again with a fresh clone but it seems the hiccup disappeared also in my setup now. Sorry for the false alarm.

As the package-lock.json file is currently checked into the repo, would it make sense to update the instructions to npm ci instead of npm install in the README?

@chgeo
Copy link
Member

chgeo commented Jul 29, 2024

As the package-lock.json file is currently checked into the repo, would it make sense to update the instructions to npm ci instead of npm install in the README?

Done

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

Successfully merging this pull request may close these issues.

2 participants