I've had a Ruby on Rails project for several years set up with Semaphore CI. The Semaphore project is set to use Ruby 2.2.2 as it's language. Over time the project adopted npm with browserify and babelify, and we're using all the latest ES6 features. We added npm install as a setup step to our Semaphore build, and this was working fine.
Now we are starting to use Jest to test our javascripts, and this is working fine locally. But when I added npm test to our Semaphore test commands, npm test fails on semaphore CI with the following errors:
FAIL app/assets/javascripts/tests/selectors/conversations.test.js
● Test suite failed to run
SyntaxError: Unexpected token {
at _load_jsdom (node_modules/jest/node_modules/jest-cli/node_modules/jest-environment-jsdom/build/index.js:17:41)
FAIL app/assets/javascripts/tests/reducers/conversations.test.js
● Test suite failed to run
SyntaxError: Unexpected token {
at _load_jsdom (node_modules/jest/node_modules/jest-cli/node_modules/jest-environment-jsdom/build/index.js:17:41)
Test Suites: 2 failed, 2 total
Tests: 0 total
Snapshots: 0 total
Time: 0.65s
Ran all test suites.
npm ERR! Test failed. See above for more details.
This is some relavent information from the project's package.json:
"scripts": {
"test": "jest --debug --verbose"
},
"jest": {
"roots": [
"<rootDir>/app/assets/javascripts"
]
},
"dependencies": {
"babel-plugin-syntax-async-functions": "^6.3.13",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-regenerator": "^6.3.18",
"babel-polyfill": "^6.3.14",
"babel-preset-env": "^1.5.2",
"babel-preset-es2015": "^6.24.1",
"babel-preset-es2016": "^6.24.1",
"babel-preset-es2017": "^6.24.1",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"babelify": "^7.2.0",
"browserify": "^14.0.0",
"browserify-incremental": "^3.1.0",
"es6-promise": "^3.0.2",
"fetch": "^0.3.6"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-jest": "^22.1.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"bootstrap": "^4.0.0-beta.3",
"browserify": "^14.4.0",
"browserify-incremental": "^3.1.1",
"jest": "^22.1.1"
}
This is the .babelrc file located in the project :
{
"presets": ["env", "es2015", "es2016", "es2017", "stage-0", "react"]
}
Locally, I am on node v7.10.0. I SSH'ed into my Semaphore CI session and discovered that node v4.8.4 is installed there. I tried installing node v4.8.4 on my local machine and with that version installed, I get the same test errors (posted above) locally as I did on CI. So this is a node version issue.
I added:
"engines": {
"node": ">= 7.1.0"
}
to my package.json file, but that did not affect the node version installed on Semaphore.
So if I already have Ruby 2.2.2 chosen as my language and version in the Semaphore Build Settings, how to I change my node version?
Thanks in advance for the help.
It looks like SemaphoreCI is not using the same version of NPM as you. But you can set that within the build settings like this :
nvm install v8.9.4
npm install
npm test
You can test it out in the SSH
Ervin from Semaphore here,
To change the current Node.js version in the environment, whilst Ruby 2.2 is selected, add nvm use 7.1 to your setup steps. This will switch to the desired Node.js version and everything should work as expected. There's also an example of this in the docs.
Get in touch on support if you run into any issues.
Related
This time I am trying to use a npm web3 package in laravel 5.2 project. I am completely new using npm and that too inside laravel.
So far I have below things in my package.json file -
{
"private": true,
"devDependencies": {
"gulp": "^3.9.1"
},
"dependencies": {
"bootstrap-sass": "^3.0.0",
"laravel-elixir": "^2.0.0",
"web3": "^1.0.0-beta.36"
}
}
When I do npm install all the node dependencies are installed in node_modules inside root directory. Now I am trying to figure out how this packages can be bought in use inside public/assets/js/app.js file.
Do I also have to make node services running to use this packages?
npm version: 6.4.1
node version: v8.11.4
Your help is much appreciated.
Updated question - 10th Sep 2018
Downgraded my node package to 6.0 due to overcome few issues with 8.0 I was facing.
node version: v6.0.0
npm version: 3.8.6
New package.json:
{
"private": true,
"scripts": {
"prod": "gulp --production",
"dev": "gulp watch"
},
"devDependencies": {
"#types/node": "^10.9.4",
"gulp": "^3.9.1",
"laravel-elixir-rollup": "^0.3.3",
"laravel-elixir-webpack": "^1.0.1",
"require-dir": "^0.3.2"
},
"dependencies": {
"bootstrap-sass": "^3.0.0",
"laravel-elixir": "^5.0.0",
"web3": "^1.0.0-beta.36"
}
}
New gulpfile.json:
var elixir = require('laravel-elixir');
var path = require('path');
require('laravel-elixir-webpack');
elixir(function(mix) {
mix.webpack(
'./node_modules/web3/src/index.js',
'./public/js/web3-compiled.js'
);
});
When I run npm run dev in console, it stops finishes as below -
[digvijay#Digvijays-MacBook-Air:/var/www/html/estatebaron$ npm run dev
> # dev /private/var/www/html/estatebaron
> gulp watch
node_modules/nan
[17:10:07] Using gulpfile /private/var/www/html/estatebaron/gulpfile.js
[17:10:07] Starting 'watch'...
[17:10:07] Finished 'watch' after 18 ms
What I am expecting here is a js file name web3-compiled.js created in public/js directory, but that does not happen now. Am I missing anything here.
If you are using default laravel 5.2 configuration you're probably missing some lines in package.json see this
So to make it work run npm run dev, but make sure to configure your gulp correctly with gulpfile.js. Read more about this in the https://laravel.com/docs/5.3/elixir and https://github.com/gulpjs/gulp/tree/v3.9.1/docs
Question
What is wrong with my Dockerfile or bitbucket-pipelines.yml? Why are modules missing from the bitbucket pipelines environment?
Error
When I try to npm run build my Vue2 project with webpack using Bitbucket Pipelines, I get errors regarding missing modules.
From Logs
npm run build
> people-is#1.0.0 build /opt/atlassian/pipelines/agent/build
> node build/build.js
module.js:549
throw err;
^
Error: Cannot find module 'cli-spinners'
Files
Here are the files for configuration.
Dockerfile - builds cportwine/people-is
FROM node:8.10.0
RUN npm install
RUN npm install -g firebase-tools
CMD [ "npm", "run", "build" ]
bitbucket-pipelines.yml
image:
name: cportwine/people-is
pipelines:
default:
- step:
script:
- npm run build
package.json
{
"name": "people-is",
"version": "1.0.0",
"description": "A Vue.js project",
"author": "cportwine",
"private": true,
"scripts": {
"dev": "node build/dev-server.js",
"start": "node build/dev-server.js",
"build": "node build/build.js",
"deploy": "firebase deploy --token $FIREBASE_TOKEN"
},
"dependencies": {
"rxjs": "^5.5.8",
"uuid": "^3.2.1",
"vue": "^2.5.16",
"vue-json-excel": "^0.1.9",
"vue-router": "^2.8.1",
"vue-rx": "^5.0.0",
"vuefire": "^1.4.5",
"vuetify": "^0.15.2"
},
"devDependencies": {
"autoprefixer": "^7.2.6",
"babel-core": "^6.22.1",
"babel-loader": "^7.1.4",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-preset-env": "^1.6.1",
"babel-preset-stage-2": "^6.22.0",
"babel-register": "^6.22.0",
"chalk": "^2.3.2",
"connect-history-api-fallback": "^1.5.0",
"copy-webpack-plugin": "^4.5.1",
"css-loader": "^0.28.11",
"cssnano": "^3.10.0",
"eslint": "^4.19.1",
"eslint-config-standard": "^11.0.0",
"eslint-friendly-formatter": "^3.0.0",
"eslint-loader": "^1.9.0",
"eslint-plugin-html": "^4.0.2",
"eslint-plugin-promise": "^3.7.0",
"eslint-plugin-standard": "^3.0.1",
"eventsource-polyfill": "^0.9.6",
"express": "^4.16.3",
"extract-text-webpack-plugin": "^2.0.0",
"file-loader": "^0.11.1",
"firebase": "^4.12.0",
"firebase-tools": "^3.17.7",
"friendly-errors-webpack-plugin": "^1.1.3",
"html-webpack-plugin": "^2.28.0",
"http-proxy-middleware": "^0.17.3",
"opn": "^5.3.0",
"optimize-css-assets-webpack-plugin": "^2.0.0",
"ora": "^1.4.0",
"rimraf": "^2.6.0",
"semver": "^5.5.0",
"shelljs": "^0.7.6",
"url-loader": "^0.5.8",
"vue-loader": "^13.7.1",
"vue-style-loader": "^3.1.2",
"vue-template-compiler": "^2.5.16",
"vuex": "^2.5.0",
"webpack": "^2.6.1",
"webpack-bundle-analyzer": "^2.11.1",
"webpack-dev-middleware": "^1.12.2",
"webpack-hot-middleware": "^2.21.2",
"webpack-merge": "^4.1.2"
},
"engines": {
"node": ">=8.10.0",
"npm": ">= 5.6.0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
],
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://chaddportwine#bitbucket.org/jahnelgroup/people-is.git"
},
"keywords": [],
"license": "ISC",
"homepage": "https://bitbucket.org/jahnelgroup/people-is#readme"
}
What I see
When I ls the node_modules folder in both environments, they do not match. Modules are missing from bitbucket pipelines.
local folder
people-is/node_modules
...
chalk
char-spinner
chardet
check-types
chokidar
chownr
cipher-base
circular-json
cjson
clap
class-utils
clean-css
cli-boxes
cli-cursor
cli-spinners
cli-table
cli-table2
cli-width
cliui
...
bitbucket folder
/opt/atlassian/pipelines/agent/build/node_modules
Woah, missing modules!
...
chalk
cli-cursor
co
...
What I have tried
I added a command to the bitbucket-pipelines.yml to npm install before I build.
bitbucket-pipelines.yml
image:
name: cportwine/people-is
pipelines:
default:
- step:
script:
- npm install
- npm run build
This adds some additional modules (like cli-spinners from the error) to /opt/atlassian/pipelines/agent/build/node_modules.
bitbucket folder
/opt/atlassian/pipelines/agent/build/node_modules
...
chalk
char-spinner
chardet
check-types
chokidar
chownr
cipher-base
circular-json
cjson
clap
class-utils
clean-css
cli-boxes
cli-cursor
cli-spinners
cli-table
cli-table2
cli-width
cliui
clone
clone-response
co
...
However, the build command still fails, due to a different missing module.
Error
> people-is#1.0.0 build /opt/atlassian/pipelines/agent/build
> node build/build.js
module.js:549
throw err;
^
Error: Cannot find module './_safeGet'
Solutions
I can now build the app, but I don't know why!
1 - Simplify the Dockerfile
I removed all the npm commands. Maybe the npm install commands were redundant? There was no advantage using the Docker Image to pre-install npm packages.
2 - Remove Node_Modules before install
Using the bitbucket-pipelines.yml, remove the node_modules folder, and then perform npm install -g npm and npm install and npm install -g firebase-tools.
File Changes
bitbucket-pipelines.yml (added lines)
image:
name: cportwine/people-is
pipelines:
default:
- step:
script:
- rm -r node_modules <---- remove
- npm install -g npm <---- install
- npm install <---- install
- npm install -g firebase-tools <---- install
- npm run build
Dockerfile (lines removed)
FROM node:8.10.0
<---- remove
CMD [ "npm", "run", "build" ]
Answer ?
I'm not sure why moving all the npm install stuff into the bitbucket.pipelines.yml solved my issue building the project. I thought Docker would enable me to define my environment, e.g., install a version of node/npm and firebase. And pipelines would "run" that.
If someone could explain what I am missing, I would accept that answer.
Answer
I received support from the Atlassian Team
Leave npm install -g firebase in the docker image.
Move npm install from the docker image to the
bitbucket-pipelines.yml file.
Reason
The node_modules folder was listed in .gitignore
tl;dr
My mistake - I forgot about .gitignore and how that affects the node_modules folder in source control, e.g., Bitbucket Pipelines.
I was looking at my local node_modules folder and building locally which worked.
However
The node_modules in source control, by design, is not in-sync with my local folder because it's included in the .gitignore file.
So
It was necessary for me to rm node_modules and npm install using the bitbucket-pipelines.yml. Now, BitPipes finds the modules I have installed locally.
This is sort of the point of maintaining the package.json, but I got confused.
I am trying to deploy a Sails.js app to Bluemix and we are getting the following error during the deploy stage in the toolchain on Bluemix (When the CF PUSH command is called):
npm ERR! Cannot read property 'pause' of undefined
I understand the trace goes to the npm-error.log file, however, I haven't been able to get to it as we cannot ssh in to see whats in the file as the application is in its "off" state after a bad deploy.
This same code was successfully deployed with both Cf push {app name}} and through a simple build and deploy toolchain in Bluemix just 8 days ago.
In the build stage I can run Npm install and npm update just fine. However, it seems to do this again in the deploy stage regardless and it fails. Here is some detail on this failure
NODE_ENV=production
NPM_CONFIG_LOGLEVEL=error
NPM_CONFIG_PRODUCTION=true
Visit http://docs.cloudfoundry.org/buildpacks/node/index.html#vendoring
NODE_HOME=/tmp/app/.cloudfoundry/0/node
NODE_MODULES_CACHE=true
NODE_VERBOSE=false
Restoring cache
Loading 3 from cacheDirectories (default):
- .npm
- .cache/yarn (not cached - skipping)
- bower_components (not cached - skipping)
Installing node modules (package.json) Building dependencies
sails#0.12.13 preinstall /tmp/app/node_modules/sails
node ./lib/preinstall_npmcheck.js
Sails.js Installation: Checking npm-version successful
npm ERR! Cannot read property 'pause' of undefined
npm ERR! /tmp/app/.npm/_logs/2017-09-09T17_02_48_660Z-debug.log
**ERROR** Unable to build dependencies: exit status 1
Failed to compile droplet
Exit status 223
Staging failed: Exited with status 223
Destroying container
npm ERR! A complete log of this run can be found in:
Successfully destroyed container
Package.json file
{
"name": "myApp",
"private": true,
"version": "0.0.1",
"description": "Stuff my app does",
"keywords": [
"Cool Apps"
],
"dependencies": {
"bcryptjs": "^2.4.3",
"cacheman": "^2.2.1",
"ejs": "2.3.4",
"elasticsearch": "^13.0.0-rc2",
"find-remove": "^1.0.1",
"fs": "0.0.1-security",
"grunt": "1.0.1",
"grunt-contrib-clean": "1.0.0",
"grunt-contrib-coffee": "1.0.0",
"grunt-contrib-concat": "1.0.1",
"grunt-contrib-copy": "1.0.0",
"grunt-contrib-cssmin": "1.0.1",
"grunt-contrib-jst": "1.0.0",
"grunt-contrib-less": "1.3.0",
"grunt-contrib-uglify": "1.0.1",
"grunt-contrib-watch": "1.0.0",
"grunt-sails-linker": "~0.10.1",
"grunt-sync": "0.5.2",
"include-all": "^1.0.0",
"jsonwebtoken": "^7.3.0",
"moment": "^2.18.1",
"moment-timezone": "^0.5.13",
"passport": "^0.2.x",
"passport-http-bearer": "^1.0.1",
"passport-idaas-openidconnect": "^1.1.0",
"passport-local": "^1.0.0",
"rc": "1.0.1",
"request": "^2.81.0",
"request-promise": "^4.2.0",
"sails": "~0.12.13",
"sails-disk": "~0.10.9",
"sails-mongo": "^0.12.2",
"stream": "0.0.2",
"uuid-1345": "^0.99.6",
"validator": "^7.0.0",
"natural-sort": "^1.0.0"
},
"scripts": {
"start": "node app.js"
},
"engines": {
"node": "^8.0.x",
"npm": "^5.0.x"
},
"main": "app.js",
"author": "Scott N",
"license": ""
}
Things I've tried so far.
-change node versions
-changed npm versions
-change dependencies versions to include the ^ prefix
-removed all dependencies but Sails in the package.json file
So Sails.js and the Nodebuildpack/Bluemix aren't playing well with each other.
Any help would be appreciated.
Thank you
It happens to me just the same. and I've to roll back the prev version of npm: 5.3.0 and it's working now. (BTW: macOS)
The error only happens when I update my npm version like this:
Update available 5.3.0 → 5.4.1
Run npm i -g npm to update
The best way to handle it is to update your package.json to use engines like so
"description": "a Sails application",
"keywords": [],
"engines": {
"node": "6.10.1",
"npm": "5.3.0"
},
Got this issue while trying to push to heroku which seems to be the npm version specified by #m-t, and also specifying the versions like above makes ibm bluemix pick it up as default node engine instead of using the latest stable version.
And don't forget to always specify your node and npm versions directly, instead of adding tilde or caret, this just to be safe. check https://stackoverflow.com/a/22345808/5836034 for more about tilde and caret
you can still check #sai-vennam answer here for more info
So I rolled back the sails version in the package.json file from 0.12 to 0.11 and it deployed fine. So CF PUSH and the newest sails version are not getting along on Bluemix. This was using Node 8.0 and NPM version ^5.0.x
I am now unable to run tests, I was able to run the basic sum.js test on jests tutorial page, but am unable to test my react code. I've seen on other sites that moving the node 4.x fixes the issue, but not for me. Any help is appreciated.
C:\wamp\www\ccRelaunchWorkspace>node -v
v4.3.0
I am running windows 7
"devDependencies": {
"babel-jest": "^9.0.0",
"babel-polyfill": "*",
"babel-preset-es2015": "*",
"babel-preset-react": "*",
"jest-cli": "*",
"react-addons-test-utils": "~0.14.0"
},
"scripts": {
"test": "jest"
},
"jest": {
"scriptPreprocessor": "./node_modules/babel-jest",
"unmockedModulePathPatterns": [
"./node_modules/react",
"./node_modules/react-dom",
"./node_modules/react-addons-test-utils"
]
},
error:
Using Jest CLI v0.7.0
Error reading file: `C:\wamp\www\ccRelaunchWorkspace\node_modules\babel-preset-e
s2015\node_modules\babel-plugin-transform-es2015-parameters\node_modules\babel-t
raverse\node_modules\babel-code-frame\node_modules\chalk\node_modules\ansi-style
s\package.json`
C:\wamp\www\ccRelaunchWorkspace\node_modules\jest-cli\node_modules\node-haste\li
b\loader\ResourceLoader.js:88
throw err;
^
Error: EMFILE: too many open files, open 'C:\wamp\www\ccRelaunchWorkspace\node_m
odules\babel-preset-es2015\node_modules\babel-plugin-transform-es2015-parameters
\node_modules\babel-traverse\node_modules\babel-code-frame\node_modules\chalk\no
de_modules\ansi-styles\package.json'
at Error (native)
npm ERR! Test failed. See above for more details.
npm ERR! not ok code 0
I have completely remove all modules, and moved all of my modules into dependencies, instead of having some in devDependencies, and removed the version numbers on anything jest related and replaces the versions with * and then ran npm install
I'm setting up a Jenkins build on Windows Server 2012 R2 Standard. Part of the build involves using npm to install from package.json:
package.json
{
"name": "localtest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": url_for_git_repo
},
"author": "",
"license": "ISC",
"devDependencies": {
"extract-text-webpack-plugin": "^0.8.2",
"jasmine-core": "^2.3.4",
"karma": "^0.13.9",
"karma-chrome-launcher": "^0.2.0",
"karma-jasmine": "^0.3.6",
"karma-mocha-reporter": "^1.1.1",
"karma-phantomjs-launcher": "^0.2.1",
"karma-sourcemap-loader": "^0.3.5",
"karma-webpack": "^1.7.0",
"node-sass": "^3.3.1",
"phantomjs": "^1.9.18",
"raw-loader": "^0.5.1",
"sass-loader": "^2.0.1",
"webpack": "^1.12.0"
}
}
When I run npm install from command line it works successfully but it fails when the Jenkins build attempts it. The full Jenkins output can be viewed on pastebin. The specific error seems to be LINK : fatal error LNK1181: cannot open input file 'C:\Windows\system32\config\systemprofile\.node-gyp\0.12.7\Release\node.lib' [C:\bld\localtest\node_modules\karma\node_modules\socket.io\node_modules\engine.io\node_modules\ws\node_modules\utf-8-validate\build\validation.vcxproj]. The folder Release doesn't actually exist on my system so that would seem to be a sensible error message other than the fact that the install completes successfully from command line (both cmd.exe and git bash FWIW).
With this working from command line I think the problem is related to some environment variable or other, or maybe something with the path but having tried to replicate the path from the command line into the Jenkins build I still haven't had any joy. Does anyone have any suggestions for what I might try next?
UPDATE 1:
I've just set the Jenkins service to log on under my account rather than the system account and restarted it. The build completed successfully. I think that makes it even more likely that this is a problem in the environment variables somewhere.
UPDATE 2:
I installed the Environment Injector plugin for Jenkins so that I could update the environment variables which were different between my user and the system user. This still resulted in the same error.
This isn't much of an answer, but it's what worked out for me.
I ended up doing
npm uninstall -g node-gyp
And then uninstalling nodejs. I then re-installed nodejs and ran
npm install -g node-gyp
And the Jenkins build is now running successfully