node.jsnpmgruntjsthrift

thrift npm instalation fails


I am trying to install the NPM package thirft in my angular project. I added to mi package.json:

"@types/thrift": "^0.10.9",
"thrift": "^0.13.0",
"node-int64": "^0.4.0",

Then I run npm Install All seems to go smooth.

As stated in the npm package webpage I have to grunt the package to finish its instalaltion. Following the steps I got to the package and execute: npm install npx grunt

And then I get this error

Running "shell:ThriftGen" (shell) task
>> /bin/sh: 1: ../../compiler/cpp/thrift: not found 
Warning: Done, with errors: command "mkdir -p test/gen-js && ../../compiler/cpp/thrift -gen js --out test/gen-js ../../test/ThriftTest.thrift && ../../compiler/cpp/thrift -gen js --out test/gen-js ../../test/JsDeepConstructorTest.thrift && mkdir -p test/gen-js-jquery && ../../compiler/cpp/thrift -gen js:jquery --out test/gen-js-jquery ../../test/ThriftTest.thrift && mkdir -p test/gen-nodejs && ../../compiler/cpp/thrift -gen js:node --out test/gen-nodejs ../../test/ThriftTest.thrift && mkdir -p test/gen-js-es6 && ../../compiler/cpp/thrift -gen js:es6 --out test/gen-js-es6 ../../test/ThriftTest.thrift && mkdir -p test/gen-nodejs-es6 && ../../compiler/cpp/thrift -gen js:node,es6 --out ./test/gen-nodejs-es6 ../../test/ThriftTest.thrift" (target "ThriftGen") exited with code 127. Use --force to continue.                                                                                                                                                                                                                                                     
Aborted due to warnings. 

It fell that using force will not correct the underlying problem but ignore it and end in a erroneous installation.


Solution

  • Edit from Feb. 23, 2021:

    Since a few days, Apache thrift 0.14.0 has been released. This should solve the aforementioned issues. Please give it a try and open a new question if you experience any problems. See https://www.npmjs.com/package/thrift

    Original Answer:

    As of now (thrift 0.13.0) there are multiple issues with the Node.js package. The issues are documented here:

    All of these issues have been fixed in upstream master branch at https://github.com/apache/thrift. But the fixes have not been released to npm yet.

    If you urgently need a working thrift, I recommend building it yourself from the sources. This will require a bit of fiddling, but its not impossible. Generally for this kind of request its best if you ask at the users mailing list at https://thrift.apache.org/mailing. But I'll try to outline the relevant steps here.

    You will need to create a local Node.js package that you can use in place of the usual npm install command. See the Node.js package documentation for more details. This Node.js package does not include the thrift compiler, so it is not sufficient to generate new Thrift bindings from an IDL file. If you need the compiler too, it may be easiest to install it from binary distributors (like your Linux distribution, if you have that). Apache Thrift itself does not provide ready-made binaries.

    Here are the required steps to generate the Node.js bundle:

    1. Clone the Thrift master branch from https://github.com/apache/thrift
    2. Open a terminal and go to the root folder of the checkout
    3. Call npm install to install build dependencies
    4. Package a local Node.js bundle of Thrift with npm pack This will (as of now) create a local bundle thrift-0.14.0.tgz with the latest Node.js sources for Thrift.
    5. Copy this to your Angular project, then install it using npm --save "file:thrift-0.14.0.tar.gz"