Errore durante l'installazione di bcrypt con npm


90

Non riesco a eseguire l'installazione bcryptutilizzando npmsulla mia macchina perché riscontro i seguenti errori. Ho risolto il problema senza molta fortuna. Potete consigliarmi dei passaggi per diagnosticare o risolvere il problema in modo da poter eseguire npm install bcryptcorrettamente?

Someones-Macbook:node_modules Cody$ npm install bcrypt
npm WARN package.json grunt-contrib-htmlmin@0.1.3 No README data
|
> bcrypt@0.7.7 install /Applications/MAMP/htdocs/richintime/ultimate-seed/node_modules/bcrypt
> node-gyp rebuild

child_process: customFds option is deprecated, use stdio instead.
  CXX(target) Release/obj.target/bcrypt_lib/src/blowfish.o
  CXX(target) Release/obj.target/bcrypt_lib/src/bcrypt.o
  CXX(target) Release/obj.target/bcrypt_lib/src/bcrypt_node.o
../src/bcrypt_node.cc:118:18: error: no member named 'Dispose' in 'v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function>
      >'
        callback.Dispose();
        ~~~~~~~~ ^
../src/bcrypt_node.cc:202:19: error: unknown type name 'uv_work_t'
void GenSaltAsync(uv_work_t* req) {
                  ^
../src/bcrypt_node.cc:219:24: error: unknown type name 'uv_work_t'
void GenSaltAsyncAfter(uv_work_t* req) {
                       ^
../src/bcrypt_node.cc:220:17: error: calling a protected constructor of class 'v8::HandleScope'
    HandleScope scope;
                ^
/Users/Cody/.node-gyp/0.12.0/deps/v8/include/v8.h:816:13: note: declared protected here
  V8_INLINE HandleScope() {}
            ^
../src/bcrypt_node.cc:228:44: error: no member named 'New' in 'v8::String'
        argv[0] = Exception::Error(String::New(baton->error.c_str()));
                                   ~~~~~~~~^
../src/bcrypt_node.cc:229:19: error: no matching function for call to 'Undefined'
        argv[1] = Undefined();
                  ^~~~~~~~~
/Users/Cody/.node-gyp/0.12.0/deps/v8/include/v8.h:305:28: note: candidate function not viable: requires single argument 'isolate', but no
      arguments were provided
  friend Handle<Primitive> Undefined(Isolate* isolate);
                           ^
../src/bcrypt_node.cc:232:19: error: no matching function for call to 'Undefined'
        argv[0] = Undefined();
                  ^~~~~~~~~
/Users/Cody/.node-gyp/0.12.0/deps/v8/include/v8.h:305:28: note: candidate function not viable: requires single argument 'isolate', but no
      arguments were provided
  friend Handle<Primitive> Undefined(Isolate* isolate);
                           ^
../src/bcrypt_node.cc:238:20: error: member reference type 'v8::Persistent<v8::Function>' is not a pointer; maybe you meant to use '.'?
    baton->callback->Call(Context::GetCurrent()->Global(), 2, argv);
    ~~~~~~~~~~~~~~~^~
                   .
../src/bcrypt_node.cc:238:22: error: no member named 'Call' in 'v8::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function> >'
    baton->callback->Call(Context::GetCurrent()->Global(), 2, argv);
    ~~~~~~~~~~~~~~~  ^
../src/bcrypt_node.cc:238:36: error: no member named 'GetCurrent' in 'v8::Context'
    baton->callback->Call(Context::GetCurrent()->Global(), 2, argv);
                          ~~~~~~~~~^
../src/bcrypt_node.cc:246:34: error: unknown type name 'Arguments'; did you mean 'v8::internal::Arguments'?
Handle<Value> GenerateSalt(const Arguments &args) {
                                 ^~~~~~~~~
                                 v8::internal::Arguments
/Users/Cody/.node-gyp/0.12.0/deps/v8/include/v8.h:127:7: note: 'v8::internal::Arguments' declared here
class Arguments;
      ^
../src/bcrypt_node.cc:247:17: error: calling a protected constructor of class 'v8::HandleScope'
    HandleScope scope;
                ^
/Users/Cody/.node-gyp/0.12.0/deps/v8/include/v8.h:816:13: note: declared protected here
  V8_INLINE HandleScope() {}
            ^
../src/bcrypt_node.cc:249:32: error: type 'const v8::internal::Arguments' does not provide a subscript operator
    const ssize_t rounds = args[0]->Int32Value();
                           ~~~~^~
../src/bcrypt_node.cc:250:30: error: type 'const v8::internal::Arguments' does not provide a subscript operator
    const int rand_len = args[1]->Int32Value();
                         ~~~~^~
../src/bcrypt_node.cc:251:58: error: type 'const v8::internal::Arguments' does not provide a subscript operator
    Local<Function> callback = Local<Function>::Cast(args[2]);
                                                     ~~~~^~
../src/bcrypt_node.cc:255:45: error: 'New' is a private member of 'v8::PersistentBase<v8::Function>'
    baton->callback = Persistent<Function>::New(callback);
                                            ^
/Users/Cody/.node-gyp/0.12.0/deps/v8/include/v8.h:572:23: note: declared private here
  V8_INLINE static T* New(Isolate* isolate, T* that);
                      ^
../src/bcrypt_node.cc:255:57: error: too few arguments to function call, expected 2, have 1
    baton->callback = Persistent<Function>::New(callback);
                      ~~~~~~~~~~~~~~~~~~~~~~~~~         ^
/Users/Cody/.node-gyp/0.12.0/deps/v8/include/v8.h:572:3: note: 'New' declared here
  V8_INLINE static T* New(Isolate* isolate, T* that);
  ^
/Users/Cody/.node-gyp/0.12.0/deps/v8/include/v8config.h:289:20: note: expanded from macro 'V8_INLINE'
# define V8_INLINE inline __attribute__((always_inline))
                   ^
../src/bcrypt_node.cc:259:5: error: unknown type name 'uv_work_t'
    uv_work_t* req = new uv_work_t;
    ^
../src/bcrypt_node.cc:259:26: error: unknown type name 'uv_work_t'
    uv_work_t* req = new uv_work_t;
                         ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [Release/obj.target/bcrypt_lib/src/bcrypt_node.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.emit (events.js:110:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1067:12)
gyp ERR! System Darwin 13.4.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Applications/MAMP/htdocs/richintime/ultimate-seed/node_modules/bcrypt
gyp ERR! node -v v0.12.0
gyp ERR! node-gyp -v v1.0.2
gyp ERR! not ok 
npm ERR! Darwin 13.4.0
npm ERR! argv "node" "/usr/local/bin/npm" "install" "bcrypt"
npm ERR! node v0.12.0
npm ERR! npm  v2.7.1
npm ERR! code ELIFECYCLE

npm ERR! bcrypt@0.7.7 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the bcrypt@0.7.7 install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the bcrypt package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild

Risposte:


211

La soluzione più semplice è passare dal modulo npm "bcrypt" a bycryptjso bcrypt-nodejs. È la stessa identica API, ma JS puro, quindi nessun componente aggiuntivo nativo da gestire.

npm install --save bcryptjs && npm uninstall --save bcrypt

Quindi cambia il tuo require chiamate in "bcryptjs", ma tutto il tuo codice altrimenti può essere invariato.

A lungo termine, sospetto che al momento bcrypt potrebbe non essere ancora pronto per il nodo v0.12.0, ma in caso contrario verrà aggiornato e pronto.


1
2,7 volte più lenta della versione Python
— rocketspacer

1
bcryptjs funziona per me. bcrypt-nodejs NON lo fa, però.
— Colby Cox

4
2019 - sembra che bcrypt-nodejs non sia più supportato
— Matt

1
è una correzione, non LA correzione. se non puoi passare alla versione del nodo di bcrypt, vai per l'installazione di node-gyp (prova npm i bcrypt npde-gyp --force) quindi prova npm i. dovrebbe costruire correttamente.
— Caio Wilson

1
Ho installato bcrypt-nodejs anche se è già deprecato, quindi l'ho rimosso e ho installato di nuovo bcrypt. In questo modo, ho installato bcrypt con successo e ha funzionato bene.
— prettydev

34

per Windows installa il seguente modulo

npm install -g node-gyp
npm install --g --production windows-build-tools

quindi prova ad installare

npm install bcrypt

Questo ragazzo dà una risposta perfetta. altre cose sono deprecate.
— Gaurang Joshi

dopo tutte queste cose, dovresti anche aggiungere l' pythoneseguibile alla tua variabile d'ambiente PATH , in modo che l'installatore lo trovi, sembra che ne abbia bisogno per eseguire correttamente l'installazione.
— Rakibul Haq

Puoi farlo facendo clic con il tasto destro su Powershell e selezionando "Esegui come amministratore"
— Kishan Patel

Assicurati anche di chiudere qualsiasi altro terminale (dato che non uso Powershell per impostazione predefinita) per windows-build-toolscompletare l'installazione. Grazie per questa risposta btw
— 3Dos

Esegui come amministratore su Windows
— Prathamesh More

10

Su questo comando:

npm install --g --production windows-build-tools

Potrebbe essere necessario eseguirlo in Powershell come amministratore sulla macchina Windows.

A tale scopo, fai clic con il pulsante destro del mouse su Powershell e seleziona "Esegui come amministratore"


5

La soluzione accettata funziona ma bcryptjs è più lento della versione python e c ++.

Se vuoi ancora bcrypt invece di bcryptjs, la soluzione funzionante è il comando seguente, ma possono anche avere problemi.

✔️ npm install -g node-gyp
❌ npm install --g --production windows-build-tools

In Windows il secondo comando proverà ad installare Visual Studio insieme a Python e quindi sorge il problema. perché dovremmo voler installare Visual Studio e ci vuole molto tempo. e ostacola anche l'installazione di python. E se dimentichi di eseguire quei comandi come amministratore, verranno installati in C: \ Users \ User.windows-build-tools che inoltre non funzionerà perché il nodo cercherà python in C: \ o C: \ Program Files \ . Quindi questi comandi in alcuni casi aumentano le tue complicazioni.

Quindi l'idea migliore per te è ✔️install python manualmente per tutti gli utenti e non è necessario aggiungere python al percorso dell'ambiente. Ed esegui solo il primo comando, ad es

✔️ npm install -g node-gyp

Ora sei pronto per installare bcrypt

npm install bcrypt

3

Su Mac OS, dopo un aggiornamento di Xcode, l'esecuzione sudo gcce l'accettazione della nuova licenza di Xcode hanno risolto il problema!


3

Ho appena eseguito quanto segue, quindi ho provato l'installazione e ha funzionato:

npm install node-pre-gyp -g

1

Stavo affrontando lo stesso problema sul lato server (aws ubuntu 16.04).

Ho provato a eliminare node_module / bcrypt da sudo rm -rf node_module/bcrypt più volte e l'ho reinstallato ancora e ancora in vari modi, ma ancora affrontare lo stesso problema.

Ho controllato la versione del nodo con nvm e mostrava anche stabile (v10.11.0).

Alla fine ho provato.

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

e ha funzionato per me.


1

Se sei su Windows, esegui PowerShell come amministratore e usa questi comandi.

npm install --g --production windows-build-tools

e quindi installa bcrypt usando

npm install --save bcrypt

1

Anch'io avevo lo stesso problema. I seguenti comandi mi hanno aiutato.

npm rebuild

poi

npm install bcrypt

1

Motivo dell'errore : il nodo potrebbe non essere in grado di trovare il percorso Python sul tuo sistema

Soluzione

passaggio: 1 Prompt dei comandi Rum come amministratore passaggio 2 Installa il pacchetto

  npm install --global --production windows-build-tools

Potrebbe volerci un po 'di tempo, sii paziente

passaggio 3 Ora installa

npm install node-gyp

Ultimo passaggio Ora sei pronto per partire

npm install bcrypt



0

Ho installato bcrypt-nodejs anche se è già deprecato, quindi l'ho rimosso e ho installato di nuovo bcrypt. In questo modo, ho installato bcrypt con successo e ha funzionato bene.

yarn add bcrypt-nodejs
yarn remove bcrypt-nodejs
yarn add bcrypt 

0

Aggiorna a bcrypt@5.0.0

npm i bcrypt@5.0.0

Non ricevo errori su questa versione più recente di bcrypt, la versione precedente dava diversi tipi di errori che vanno dall'impossibilità di installare bcrypt a errori di tipo dattiloscritto


0

In esecuzione

sudo apt install build-essential

installa tutti gli strumenti necessari per installare bcrypt su Linux. Allora puoi correre

npm install

0

Avevo la versione 12.18.3 del nodo e ho risolto lo stesso eseguendo npm i bcrypt@3.0.6


-1

Ho avuto lo stesso problema. Aggiornare npm e riprovare (installazione di npm -g npm di solito). Risolve il problema per me.

Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.