thrift npm instalation fails - node.js

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.

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:
https://issues.apache.org/jira/browse/THRIFT-5170
https://issues.apache.org/jira/browse/THRIFT-5029
https://issues.apache.org/jira/browse/THRIFT-5039
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:
Clone the Thrift master branch from https://github.com/apache/thrift
Open a terminal and go to the root folder of the checkout
Call npm install to install build dependencies
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.
Copy this to your Angular project, then install it using npm --save "file:thrift-0.14.0.tar.gz"

Related

How to install svelte, i seem to have issues with it

So I am new to javascript frameworks, and I want to start using svelte. So I went to svelte website and start the installing process, and I am already getting errors. I will keep communicating if you have any questions about my problem. Here Is my terminal:
coolstuff#srimaans-air svelte % npx degit sveltejs/template svelte-demo
! could not fetch remote https://github.com/sveltejs/template
! could not find commit hash for HEAD
coolstuff#srimaans-air svelte %
If you can't fetch the github page you might first have to install degit. You can do so with this command:
npm install -g degit
If npx isn't working you can run this:
npm install -g npx
Edit: if that didn't solve it, then it's probably that git isn't installed yet. Try what was posted here:
https://github.com/Rich-Harris/degit/issues/37
Install git and run the commands from the git terminal instead of the regular one.
Before you begin i strongly suggest you to learn how to create development environment for frameworks. There are tools such as vite, webpack.
you can easily start with vite
npm create vite#latest
or you can go with the sveltekit which also using vite
npm create svelte#latest my-app
after you set, you able to edit configuration files (vite.config.js, svelte.config.js etc) to specify output options of the pages you made.
you can find much more in here https://vitejs.dev/guide/

Plain installation of current version of Wekan on Ubuntu?

Wekan is an open-source Kanban Board which used to be easy to install using nodejs (given that you already set up your MongoDB). I am stumbling upon the actual installation steps of the guide to install Wekan on Ubuntu 16.04:
Download the latest version wekan source code using the wget command and extract it.
wget https://github.com/wekan/wekan/releases/download/v0.63/wekan-0.63.tar.gz
tar xf wekan-0.63.tar.gz
And you will get a new directory named bundle. Go to that directory and install the Wekan dependencies using the npm command as shown below.
cd bundle/programs/server
npm install
Figuring out the last stable version is easy, there are new stable versions nearly every day (as of March 2019), which somehow seem to contradict the common definition.
More importantly, the directory bundle/programs/server does not exist, only server, but it does not contain a main.js which would be necessary to run
node main.js
Other resources considered:
I did of course check the official documentation, but it looks not up-to-date. The page https://github.com/wekan/wekan/wiki/Install-and-Update is redirecting to a rather untidy page which does no longer talk about a standalone installation.
I prefer a minimal installation and not a solution using snap like described at computingforgeeks
There is also an unanswered question about a more specific installation around: Installing Wekan via Sandstorm on cPanel which follows a similar approach.
The latest releases on the Wekan page are actually no ready-to-use node builds.
Wekan is built using Meteor and you will need Meteor to create the build. This is because you could also build it using Meteor against other architectures than os.linux.x86_64.
So here is how to build the latest release as of today on your dev-machine to then deploy it:
Build it yourself
[1.] Install Meteor
curl https://install.meteor.com/ | sh
[2.] Download and extract the latest Wekan
wget https://github.com/wekan/wekan/archive/v2.48.tar.gz
tar xf wekan-2.48.tar.gz
cd wekan-2.48
[3.] Install Wekan Dependencies
./rebuild-wekan.sh
# use option 1
[4.] Install dependency Meteor packages
Now it gets dirty. Somehow the required packages are not included in the release (an issue should be opened at GH). You need to install them yourself:
# create packages dir
mkdir -p packages
cd packages
# clone packages
git clone git#github.com:wekan/wekan-ldap.git
git clone git#github.com:wekan/meteor-accounts-cas.git
git clone git#github.com:wekan/wekan-scrollbar.git
# install repo and extract packages
git clone git#github.com:wekan/meteor-accounts-oidc.git
mv meteor-accounts-oidc/packages/switch_accounts-oidc ./
mv meteor-accounts-oidc/packages/switch_oidc ./
rm -rf meteor-accounts-oidc/
cd ../
[5.] Build against your architecure
meteor build ../build --architecute os.linux.x86_64
# go grab a coffee... yes even with nvme SSD...
Once the build is ready you can go ../build and check out the wekan-2.48.tar.gz which now contains your built bundle including the described folders and files.
Use this bundle to deploy as described in the documentation.
Summary
This describes only how to create the build yourself and I am not giving any guarantee that the build package will run when deployed to your target environment.
I think there is either some issue with the way the releases are attached on GH or they explicitly want to keep it open against which arch you want to build.
In any case I would open an issue with demand for a more clear documentation and a description for reproduction of the errors your mentioned.
Further readings
https://guide.meteor.com/deployment.html#custom-deployment

How to test an `npm publish` result, without actually publishing to NPM?

One common problem I have, is that sometimes my .npmignore file is too aggressive, and I ignore files that I actually will to include in the NPM tarball.
My question is - is there a way to test the results of NPM publish, without actually publishing to NPM?
I am thinking something like this. Assuming I have a local NPM package with package name "foo"
set -e;
local proj="bar";
local path_to_foo="."
mkdir -p "$HOME/.local.npm"
npm --tarball -o "$HOME/.local.npm" # made up command, but you get the idea
(
cd "$HOME/.temp_projects"
rm -rf "$proj"
mkdir "$proj"
cd "$proj"
npm init -f
npm install "$path_to_foo"
)
copy_test_stuff -o "$HOME/.temp_projects/bar"
cd "$HOME/.temp_projects/bar"
npm test
I don't think this will work. Because whatever we include in the NPM publish tarball, might not have enough to do the full test. But maybe if we copy all the test files (including fixtures, etc) when we do copy_test_stuff, it might work?
Simply run
npm publish --dry-run
or, with tarball generation in the current directory
npm pack
In npm 6 and up, these will display what files are going to be uploaded.
I'll elaborate my comment I posted earler, (thanks Alexander Mills).
I'm a verdaccio contributor, so, I closely follow whom are implementing and how to verdaccio. I'll describe couples or examples (e2e mostly) that I've found and might be interesting or as a valid answer.
create-react-app
By far, the most popular integration. Let me give you some context, they are using lerna and have multiple packages that need to test before to publish on main registry aka (npmjs). I'll quote here Dan Abramov explaining their reasons to use a custon registry.
The script is self-explanatory but let me highlight some parts.
+nohup npx verdaccio#2.7.2 &>$tmp_registry_log &
+# Wait for `verdaccio` to boot
+grep -q 'http address' <(tail -f $tmp_registry_log)
+
+# Set registry to local registry
+npm set registry http://localhost:4873
+yarn config set registry http://localhost:4873
+
+# Login so we can publish packages
+npx npm-cli-login#0.0.10 -u user -p password -e user#example.com -r http://localhost:4873 --quotes
# Test local start command
yarn start --smoke-test
+./tasks/release.sh --yes --force-publish=* --skip-git --cd-version=prerelease --exact --npm-tag=latest
As you see, they are running verdaccio and instead a custom config file they have decided to use npm-cli-login and then they run the tests against verdaccio. When all is ready, they publish on verdaccio. As last step, later in the same file, they fetch packages with their own app.
pnpm
They have created a project called pnpm-registry-mock which is an abstraction that allows them to run verdaccio before running the tests.
"pretest:e2e": "rimraf ../.tmp/ && rimraf node_modules/.bin/pnpm && pnpm-registry-mock prepare",
"test:e2e": "preview --skip-prepublishOnly && npm-run-all -p -r pnpm-registry-mock test:tap",
"test": "npm run lint && npm run tsc && npm run test:e2e",
Basically, using npm scripts they prepare verdaccio and run the test as last step. I cannot go too much into details, since I've only saw it shallowly. But I know what it does.
Mozilla Neutrino
This is work in progress, but, it's also interesting to mention here.
+if [ "$PROJECT" == "all" ]; then
+ yarn link:all;
+ yarn validate:eslintrc;
+ yarn lint;
+ yarn build;
+ yarn test;
+else
+ yarn verdaccio --config verdaccio.yml & sleep 10;
+ yarn config set registry "http://localhost:4873";
+ npm config set registry "http://localhost:4873";
+ .scripts/npm-adduser.js;
+ yarn lerna publish \
+ --force-publish=* \
+ --skip-git \
+ --skip-npm \
+ --registry http://localhost:4873/ \
+ --yes \
+ --repo-version $(node_modules/.bin/semver -i patch $(npm view neutrino version));
+ yarn lerna exec npm publish --registry http://localhost:4873/;
+ PROJECT="$PROJECT" TEST_RUNNER="$TEST_RUNNER" LINTER="$LINTER" yarn test:create-project;
+fi
Again, the same approach, project is being built and then verdaccio is being executed and they publish all packages.
Babel.js
I know Babel.js has been experimenting with a smoke-testing for Babel 6 and have plans to integrate a registry with Babel 7. I quote Henry Zhu early this year talking about babel-smoke-tests in the same thread of create-react-app.
The experiment is called babel-smoke-tests and babel-smoke-tests/scripts/test.sh is the key file for you.
Here I see the same pattern than other projects. They are launching verdaccio and then they do their stuff.
START=$(cd scripts; pwd)/section-start.sh
END=$(cd scripts; pwd)/section-end.sh
$START 'Setting up local npm registry' setup.npm.registry
node_modules/.bin/verdaccio -l localhost:4873 -c verdaccio.yml &
export NPM_CONFIG_REGISTRY=http://localhost:4873/
NPM_LOGIN=$(pwd)/scripts/npm-login.sh
$NPM_LOGIN
$END 'Done setting up local npm registry' setup.npm.registry
scripts/bootstrap.sh
export THEM=$(cd them; pwd)
if [[ $SPECIFIC_TEST ]]; then
scripts/tests/$SPECIFIC_TEST.sh
else
scripts/tests/jquery.sh
scripts/tests/react.sh
fi
Wrap up
First of all, I hope my small research give you new ideas how to address your issue. I think npm pack solve some issues, but mocking a registry using verdaccio which is quite light and straightforward to use might be a real option for you. Some big projects are being (or getting started) using it and they follow more or less the same approach. So, Why don't try? :)
https://www.verdaccio.org/
I had the exact same problem, so I created a package called package-preview. What package-preview does is:
packs your package (it is what npm does before publish)
installs your package in a temp location
links the package to your project's node_modules
This allows you to basically require the package as a dependency in your tests. So in tests of "awesome-pkg", intead of require('../lib') you write require('awesome-pkg')
I use this package in all the pnpm repos for several months and it works really well. I also posted an article about this package that explains all the different errors that it can catch: Never ever forget to install a dependency
Referring to npm docs:
[--dry-run] As of npm#6, does everything publish would do except
actually publishing to the registry. Reports the details of what would
have been published.
Similar to --dry-run see npm pack, which figures out the files to be included and packs them into a tarball to be uploaded to the registry.
https://docs.npmjs.com/cli/v6/commands/npm-publish#description
I see too many complicated answers, but according to documentation, you just need to install your local package globally (because it will be installed on different directory)
Go to your module root directory and do
npm install . -g

Jenkins is not installing some node dependencies

I'm running a nodejs application's build on jenkins. I run node as shell script step, because I have some limitations in terms of the plugins I can install in this jenkins instance.
This is what the npm install step looks like:
#!/bin/bash +x
source ~/.bashrc
cd $WORKSPACE/ && \
nvm use 7.8.0 && node --version && npm install
The problem I have is, when npm install finishes, it doesn't install everything. If I ssh into the box where jenkins is installed and run npm install inside that project's workspace, with the same user jenkins uses, it works ok. Any ideas?
EDIT
I just realized the dependencies that it's not installing are devDependencies
The problem was I had the node env set to production, and of course, it wouldn't get the devDependencies...

Continuous integration and deployment of Node.js application on Bamboo

The application I want to implement continuous deployment on Bamboo has node modules and bower component dependencies. On the bamboo server nodejs, npm have been installed.
There are only three tasks on default job:
Source Code Checkout
Build dependencies:
npm install
bower install
Deploy to the staging server
The problem is on the second task, bamboo fails with the message "No failed tests found, a possible compilation error occurred." I don't even run any tests.
The log file is not explanatory at all:
Starting task 'Build dependencies' of type 'com.atlassian.bamboo.plugins.scripttask:task.builder.script'
Failing task since return code of [/bin/sh /home/ubuntu/bamboo-installation/temp/WEB-WEB-JOB1-8-ScriptBuildTask-4430338079602360707.sh] was 1 while expected 0
Ok, I solved the problem. The issue was the wrong node (which obviously messed things up) was installed on the bamboo server. Uninstalled the wrong one and everything worked as expected.
Good to see you solved it.
There is a setup I use and which could prevent further problems with CI:
export npm_config_prefix=.npm/
export PATH=.npm/bin:$PATH
export CI=true
npm install -g bower
bower install
npm install
This installs bower (and others like grunt-cli if you want) in your project folder so you can e.g. have a specific version, sets CI=true as advised in bower docs, and then installs all dependencies.
Bamboo AMI originally have npm version 1.4.28 installed and you are probably using a more recent version on you development environment. I had the same issue and resolved it by creating a script task to update npm version on the very beginning of my build process. Here is the script:
# update npm
curl -O -L https://npmjs.org/install.sh
chmod +x install.sh
sudo PATH=$PATH:/opt/node-0.10/bin ./install.sh

Resources