Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

README.md Example Results in Errors #501

Closed
gpresland opened this issue Oct 4, 2017 · 10 comments
Closed

README.md Example Results in Errors #501

gpresland opened this issue Oct 4, 2017 · 10 comments

Comments

@gpresland
Copy link

The example provided in the README.md:

var levelup = require('levelup')
var leveldown = require('leveldown')

// 1) Create our database
var db = levelup(leveldown('./mydb'))

// 2) put a key & value
db.put('name', 'LevelUP', function (err) {
  if (err) return console.log('Ooops!', err) // some kind of I/O error

  // 3) fetch by key
  db.get('name', function (err, value) {
    if (err) return console.log('Ooops!', err) // likely the key was not found

    // ta da!
    console.log('name=' + value)
  })
})

installed with:

npm install --save levelup leveldown

errors with the following with Node ver. 8.3.0:

test-leveldb\node_modules\levelup\lib\levelup.js:74
    throw error
    ^
InitializationError: Must provide a location for the database
    at new LevelUP (test-leveldb\node_modules\levelup\lib\levelup.js:67:13)
    at LevelUP (test-leveldb\node_modules\levelup\lib\levelup.js:45:44)
    at Object.<anonymous> (test-leveldb\index.js:5:10)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Function.Module.runMain (module.js:609:10)
    at startup (bootstrap_node.js:158:16)

and the following in Node ver. 6.11.4.

test-leveldb\node_modules\bindings\bindings.js:88
        throw e
        ^

Error: Module version mismatch. Expected 48, got 57.
    at Error (native)
    at Object.Module._extensions..node (module.js:597:18)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at bindings (test-leveldb\node_modules\bindings\bindings.js:81:44)
    at Object.<anonymous> (test-leveldb\node_modules\leveldown\leveldown.js:4:46)
    at Module._compile (module.js:570:32)
@vweevers
Copy link
Member

vweevers commented Oct 4, 2017

The documentation in our master branch is for the upcoming levelup@2 release. For the currently published levelup@1, see the old readme here or here.

Regarding the second error (Module version mismatch): it means that your installed version of leveldown was built for a different node version. Please try reinstalling leveldown and let us know how it goes.

@ralphtheninja let's release 2.0.0 soon and/or try to clarify all of this in the readme.

@ralphtheninja
Copy link
Member

@vweevers I want to get it out this week the latest.

@gpresland
Copy link
Author

gpresland commented Oct 4, 2017

I recognize the version mismatch in the second error, and created a fresh folder with the 6.11.4 LTS bin in the folder and nothing else. Re-created the project and receive that error. Perhaps this is a node/npm issue where it reports the system installed node version when installing the levelup/leveldown modules and ignores the node version in the folder? Running node -v in the same console that I am performing the npm init and npm install --save levelup leveldown and node . still results in this error despite showing v6.11.4.

I'll look into jumping into the 2.0.0 then.

@vweevers
Copy link
Member

vweevers commented Oct 4, 2017

created a fresh folder with the 6.11.4 LTS bin in the folder and nothing else

Do you mean that you placed a node binary in this folder? If so then yes, this is very likely to conflict with npm if that's installed globally - it won't use your local node binary.

For managing different node versions, I recommend nvm or this one if you're on Windows.

@gpresland
Copy link
Author

gpresland commented Oct 4, 2017

Do you mean that you placed a node binary in this folder?

Yes. On Windows, placing the NodeJS binary (node.exe) in a folder and running any node command in a console at the current working directory will run NodeJS with the node.exe binary in the folder rather than the globally installed NodeJS.

It seems the installation of levelup/leveldown ignores or gets an incorrect NodeJS version of the current running NodeJS version and grabs the global NodeJS version. This may be an issue with NPM/NodeJS misreports it during the npm install, I have no idea.

You can (on Windows at least, unsure about Mac/Linux) leave a node.exe binary in your project folder and it will always run with that binary. It's an alternative to nvm's method of swapping the global NodeJS, and in my opinion, can be a lot nicer if you must run a program with a specific NodeJS version. Simply leave the desired node.exe version in the folder and you're set.

@vweevers
Copy link
Member

vweevers commented Oct 4, 2017

It seems the installation of levelup/leveldown ignores or gets an incorrect NodeJS version of the current running NodeJS version and grabs the global NodeJS version. This may be an issue with NPM/NodeJS misreports it during the npm install, I have no idea.

When you run npm install, which expands to npm.cmd install, npm.cmd uses the node binary installed in the same folder as npm.cmd, and not the node binary in the current working directory.

@gpresland
Copy link
Author

gpresland commented Oct 4, 2017

When you run npm install, which expands to npm.cmd install, npm.cmd uses the node binary installed in the same folder as npm.cmd, and not the node binary in the current working directory.

Makes sense. I would have to leave the npm script and the rest of the files with the node.exe then which are all included in the zip. Only issue I have with it is that it creates a lot of 'pollution' in the directory but this issue is a digression and moot as I'll be giving [email protected] and leveldown a go as per @zixia 's suggestion here.

@vweevers
Copy link
Member

vweevers commented Oct 4, 2017

Not entirely moot, you'll still need to install leveldown ;) but it is a digression 👍

Feel free to reopen.

@vweevers vweevers closed this as completed Oct 4, 2017
@gpresland
Copy link
Author

Not entirely moot

Does [email protected] not support Node v8? Do I have to use LTS (v6)?

@vweevers
Copy link
Member

vweevers commented Oct 4, 2017

It supports both 6 and 8. I was referring to your Module version mismatch error which is not a problem with levelup (either 1 or 2) or leveldown, but your node/npm setup.

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

No branches or pull requests

3 participants