I'm currently trying to implement CI with Jenkins for an emberjs node project that uses mocha for unit testing. I'm running Jenkins on an Amazon EC2 server.
When I run mocha locally (both on my desktop, AND on the ec2 server) I get this:
./node_modules/mocha/bin/mocha
Initializing server on port 8090
Unit Test for /test
test API call incoming
key res value is: test!
✓ gives a json object with res: test!
1 passing (35ms)
However, when I have jenkins set up to run this same command:
01:44:46 + ./node_modules/mocha/bin/mocha
01:44:46
01:44:46 /var/lib/jenkins/workspace/Rekindle2_Node/server/routes/test/getTest.js:4
01:44:46 const getTest = (req, res) => {
01:44:46 ^
01:44:46 SyntaxError: Unexpected token >
etc
I've double checked, the package.json has everything I need, and I know that I don't have anything globally installed that changes things (as I managed to git clone, npm install, and run mocha from the ec2 instance). All I know is that jenkins sometimes can have issues with consuming environment variables from the server it's running on? Does anyone know what the issue I'm encountering could be? I've tried uninstalling and reinstalling node as well, it could be that Jenkins is looking at an older installation of node while the ec2 is not. Is there any way to tell this? How do I look at the environment variables of a specific build?
That looks like Jenkins is using an older version of node.js. To confirm this I would add logging to your Jenkins job. node --version will print the version of node.js that Jenkins is aware of. Also if you are interested in the environment there is a view in the Jenkins web ui to show the environment from a particular build. Or you can add env as a line in your Jenkins build script to print out the current environment variables. If it turns out to be a node.js version issue, I would look into using a plugin to manage your nodejs versions: node.js Jenkins plugin
Related
Situation
I have an Alpine/NodeJS Docker image running my app (Alpine Linux 3.11, nodeJS v12.15.0), and I recently needed to internationalize currencies in this app.
I noticed that my container was missing locales, so I needed to install full-ICU. Consequently I modified my Alpine-based Docker image to add two lines to install full-ICU:
RUN npm i -g full-icu
ENV NODE_ICU_DATA=“/home/node/.npm/lib/node_modules/full-icu”
The installation went smoothly, the console output said:
Step 10/15 : RUN npm i -g full-icu
---> Running in b14d826c8689
/home/node/.npm/bin/node-full-icu-path -> /home/node/.npm/lib/node_modules/full-icu/node-icu-data.js
> full-icu#1.3.1 postinstall /home/node/.npm/lib/node_modules/full-icu
> node postinstall.js
npm install icu4c-data#64l (Node 12.15.0 and small-icu 64.2) -> icudt64l.dat
full-icu$ /usr/bin/node /home/node/.npm/lib/node_modules/npm/bin/npm-cli.js install icu4c-data#64l
+ icu4c-data#0.64.2
added 1 package from 1 contributor in 62.073s
√ icudt64l.dat (link)
Node will use this ICU datafile if the environment variable NODE_ICU_DATA is set to “/home/node/.npm/lib/node_modules/full-icu”
or with node --icu-data-dir=/home/node/.npm/lib/node_modules/full-icu YOURAPP.js
For package.json:
{"scripts":{"start":"node --icu-data-dir=/home/node/.npm/lib/node_modules/full-icu YOURAPP.js"}}
By the way, if you have full data, running this in node:
> new Intl.DateTimeFormat('es',{month:'long'}).format(new Date(9E8));
... will show “enero”. If it shows “January” you don't have full data.
News: Please see https://github.com/icu-project/full-icu-npm/issues/6
+ full-icu#1.3.1
added 1 package from 1 contributor in 63.276s
It seems fine, it recognized my NodeJS version, there were no errors. I could check and see that the ICU data files were at the right place.
Problem
But when opening a shell inside this container (running docker run -ti myimage sh), and playing with Intl, I noticed that the locales were working properly only when running node with the --icu-data-dir option, not when using the NODE_ICU_DATA environment variable.
However, my preference definitely goes to the environment variable, for various reasons, so I would have liked it to work.
Tests so far
Here are my tests with node:
node --icu-data-dir=/home/node/.npm/lib/node_modules/full-icu
Welcome to Node.js v12.15.0.
Type ".help" for more information.
> new Intl.DateTimeFormat('es',{month:'long'}).format(new Date(9E8));
'enero'
It's saying "enero", so it's working. It means that full-ICU is properly installed and reachable.
export NODE_ICU_DATA=“/home/node/.npm/lib/node_modules/full-icu”
node
Welcome to Node.js v12.15.0.
Type ".help" for more information.
> new Intl.DateTimeFormat('es',{month:'long'}).format(new Date(9E8));
'January'
It doesn't care about my environment variable (also tried putting the environment variable in the Dockerfile, as shown above)
env NODE_ICU_DATA=“/home/node/.npm/lib/node_modules/full-icu” node
Welcome to Node.js v12.15.0.
Type ".help" for more information.
> new Intl.DateTimeFormat('es',{month:'long'}).format(new Date(9E8));
'January'
It also doesn't care when the environment variable is inlined.
I also tried with .js scripts by the way, not just the NodeJS console, and also various ways to pass the environment variable.
And just to be sure, I tried to install system ICU packages, with RUN apk --update add --no-cache icu icu-libs icu-dev.
So...
Would anyone have an idea about the reason why specifying the path in an environment variable doesn't work, and what I should check?
I have the same issue with on a VPS with Plesk.
I can't update the Node version and the installed Node version is the, v12.4.0.
In my case I can't also install full-icu as global module, and the process manager start my app without run the start script in the package.json.
In this situation for me, the only way for load the full-icu support is to use the environment vars.
I tried first via command line:
export NODE_ICU_DATA=/full/path/of/my/app/node_modules/full-icu
and then
-bash-4.2$ /opt/plesk/node/12/bin/node
Welcome to Node.js v12.4.0.
Type ".help" for more information.
> new Intl.DateTimeFormat('it',{month:'long'}).format(new Date(9E8));
'gennaio'
>
it works fine.
It works too if I run this command in the root folder of my app:
NODE_ICU_DATA=node_modules/full-icu /opt/plesk/node/12/bin/node
So I added an ENV var on the app node setting (in Plesk)
NODE_ICU_DATA
with a value
node_modules/full-icu
Restarting the app the i18n support rightly works.
I hope this could help others people there are in my same situation.
For anyone falling on this issue: the problem was version-specific.
Deploying a more recent NodeJS version fixed these ICU bugs.
Trying to generate RSA keys with crypto package and deploy it on AWS Lambda, I get an error that crypto package is undefined. Are there easy ways to deploy this package to Lambda without having building docker containers?
Yes, I read that node.js native packages have different binaries on mac (my current os) and linux, so there is an approach to build docker and deploy it, but I found it's not very clear for me, so if this is the only way to do it, maybe there are good resources to read about it also.
Thanks!
I tried to avoid docker as well but it's actually pretty easy to setup. Install the Community Edition
Pull this image with this:
docker pull lambci/lambda
To mount your dev folder run this:
docker run -v ~/[mydev-folder]:/var/task lambci/lambda:nodejs8.10
Open Kitematic from the Docker app. You should see the container you pulled. Select it and start it if it's not started. Then click "Exec" and you should get a bash prompt opened in /var/task which should be pointing at your dev folder.
I usually delete node_modules and then run npm install from inside the docker container. I also sls deploy from there was well.
You need to import the package as require("crypto"). It is just not defined on the global object.
const handler = () => {
console.log(crypto); // undefined
console.log(global.crypto); // undefined
console.log(require("crypto"); // Bingo! :D
}
If you arrived here because you are bundling a Nodejs lambda with rollup and using a version of uuid 7+, then you need to add
external: ["crypto"]
to your rollup.config.js so that rollup does not attempt to replace the require statement by whatever if finds better.
I am running my code inside a vagrant machine. In WebStorm I can specify in the run configurations to use the vagrant nodejs interpretor:
Now I need to do the same for my mocha tests, however I am unable to add a Remote Node Interpreter in my Mocha run configurations:
Does anybody have an idea how to fix that?
AFAIK that is not currently possible.
https://youtrack.jetbrains.com/issue/WEB-22179 -- watch this ticket (star/vote/comment) to get notified on any progress.
I used https://stuk.github.io/jszip/ on my local machine and update all dependency by npm and used command grunt connect but this only showing web server started but on this url its not working.
$ grunt connect
Running "connect:server" (connect) task
Started connect web server on http://localhost:9999
Done, without errors.
even i have tested the app there is no error,
can anyone let me know how to get such type of projects from git-hub and run locally by npm or composer/bower.
I have used simple javascript instead of going with NodeJs and here my code is :
Here is Gist Code you can run.
I have written an application which needs Node.js >= 4.2.6
I'm using the OpenShift service and the default Node.Js version is 0.10. Installing this https://github.com/ryanj/nodejs-custom-version-openshift is supposed to resolve this problem. So I followed the instructions and created a new application using:
rhc app create nodeapp nodejs --from-code=git://github.com/ryanj/nodejs-custom-version-openshift.git
So far so good. Next step - copy my project to the cloned git repository. Here's where I'm unsure if my approach is right (new to Node js). Because the cloned git already has a JSON package and because my app has its own JSON package in its root directory, I enriched the JSON package that came with nodejs-custom-version-openshift.git with my dependencies and set the engines to 4.2.6. The main is set to server.js. To run my app, I'm using "var variable = require('./myapp-master/test/test');" as the last line in my server.js. I copy the content of my app to the cloned repository (including node modules etc.) careful not to overwrite any existing config files like the JSON Package and then I use git push. The node version is installed properly according to the logs (upon build), servers.js is executed and it invokes my test.js. I can see in the app logs (app-root/logs) that test.js throws a specific error that indicates that the node js version is not >= 4.2.6.
When I log-in with PUTTY and write node -v, I get 4.2.6. When I navigate to my test.js and start it manually with node test.js, it runs normally. What am I doing wrong? I suspect I'm not handling the JSON packages properly (or my approach with starting my app from server.js is flawed). Any help is greatly appreciated! Thank you for your time.
Ok, I found the solution to this: https://github.com/ryanj/nodejs-custom-version-openshift/issues/2