Travis give error but compiles on pc - node.js

I'm making a web server with Node.JS and use Travis-Ci to check my code. Yhe problem I got is when I commit my code, Travis gives error below, but the code compiles without an error on my pc:
./backend/server.js: 1: Syntax error: ( unexpected
Here you could find my .travis.yml file:
install:
- npm install
- npm install -g bower
- bower install bootstrap
- bower install socket.io
language: node_js
node_js:
- "6.9"
before_script:
- chmod 0777 ./backend/server.js
cache:
directories:
- node_modules
- bower_components
and the package.json
{
"name": "watchfriends",
"version": "0.0.0",
"description": "Front-end and back-end project watchfriends",
"main": "gulpfile.js",
"scripts": {
"test": "./backend/server.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/WatchFriends/Backend.git"
},
"author": "Hein P., Jasper D., Michiel V., Michiel Z.",
"license": "ISC",
"bugs": {
"url": "https://github.com/WatchFriends/Backend/issues"
},
"homepage": "https://github.com/WatchFriends/Backend#readme",
"devDependencies": {
"gulp": "^3.9.1",
"gulp-autoprefixer": "^3.1.1",
"gulp-clean-css": "^2.0.13",
"gulp-concat": "^2.6.1",
"gulp-csslint": "^1.0.0",
"gulp-htmlhint": "^0.3.1",
"gulp-jshint": "^2.0.4",
"gulp-notify": "^2.2.0",
"gulp-sass": "^2.3.2",
"gulp-sourcemaps": "^2.2.0",
"gulp-uglify": "^2.0.0",
"jshint-stylish": "^2.2.1"
},
"dependencies": {
"socket.io": "^1.5.1"
}
}
On this gist, you could find my code, including the log.
Did I something wrong?
Thanks in advance.

Travis runs npm test when testing your code.
If you check inside of your "package.json" file then you can see that the test script is set to run ./backend/server.js. You need to run the node file with node.
Change that to node ./backend/server.js and hopefully that'll work.

Related

How to fix: The feature watch recursively is unavailable on the current platform, which is being used to run Node.js

I am trying to run a typescript express.js in a docker container. After running the docker I get the following error:
> ts-node-dev src/app.ts
Using ts-node version 8.10.1, typescript version 3.9.2
TypeError [ERR_FEATURE_UNAVAILABLE_ON_PLATFORM]: The feature watch recursively is unavailable on the current platform, which is being used to run Node.js
at Object.watch (fs.js:1441:11)
at add (/app/node_modules/filewatcher/index.js:74:34)
at /app/node_modules/filewatcher/index.js:93:5
at FSReqCallback.oncomplete (fs.js:176:5)
my Dockerfile:
FROM node:alpine
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
CMD ["npm","start"]
and the package.json file:
{
"name": "app-name",
"version": "1.0.0",
"description": "Init master",
"main": "src/app.ts",
"scripts": {
"build": "./node_modules/.bin/tsc",
"start": "ts-node-dev src/app.ts"
},
"repository": {
"type": "git",
"url": "https://*****#dev.azure.com/********"
},
"author": "",
"license": "ISC",
"dependencies": {
"celebrate": "^12.1.1",
"colors": "^1.4.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"event-dispatch": "^0.4.1",
"eventemitter3": "^4.0.0",
"express": "^4.17.1",
"helmet": "^3.22.0",
"jsonwebtoken": "^8.5.1",
"moment": "^2.25.3",
"mongoose": "^5.9.13",
"morgan": "^1.10.0",
"ms": "^2.1.2",
"pbkdf2": "^3.0.17",
"redis": "^3.0.2",
"reflect-metadata": "^0.1.13",
"status-code-enum": "^1.0.0",
"swagger-jsdoc": "^4.0.0",
"swagger-ui-express": "^4.1.4",
"ts-node": "^8.10.1",
"typedi": "^0.8.0",
"uuid": "^8.0.0",
"winston": "^3.2.1"
},
"devDependencies": {
"#types/express": "^4.17.6",
"#types/mongoose": "^5.7.16",
"#types/node": "^13.13.5",
"ts-node-dev": "^1.0.0-pre.44",
"typescript": "^3.8.3"
}
}
P.S. I have decided to include the fix:
change the Dockerfile:
FROM node:lts-alpine
and change the package.json:
"start": "ts-node-dev src/app.ts --poll"
Node v14 introduced a breaking change to the fs.watch() API, specifically that the recursive option (which has never been supported on Linux) now raises the ERR_FEATURE_UNAVAILABLE_ON_PLATFORM error if used on Linux.
A bug report and fix have been submitted to filewatcher: https://github.com/fgnass/filewatcher/pull/6
Until that fix is merged and a new version released, you'll need to stick to NodeJS < v14, or override the filewatcher package installed locally to include that patch.
It seems this error caused by node.js v14, to fix it use this command:
ts-node-dev --poll src/app.ts
Or you can use another version of node.js rather than version 14

npm run scripts does not working

I have just initialized a new project with Node.js and trying making the scripts in package.json file to be working.
For example I have the next package.json file:
{
"name": "my-app-name",
"version": "1.0.0",
"description": "Description server",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js"
},
"author": "Something LTD",
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.3",
"cron": "^1.3.0",
"crypto": "^1.0.1",
"docusaurus-init": "^1.0.2",
"exceljs": "^1.5.0",
"express": "^4.16.3",
"express-limiter": "^1.6.1",
"jsonwebtoken": "^8.3.0",
"mongojs": "^2.6.0",
"npm": "^6.1.0",
"point-in-polygon": "^1.0.1",
"request": "^2.87.0",
"socket.io": "^2.1.1",
"socket.io-redis": "^5.2.0",
"xmldom": "^0.1.27"
},
"devDependencies": {
"t4u": "^1.0.0"
}
}
Then I either trying run npm test or npm start or npm run start
but all of them just doing nothing and returns nothing in console. Even the test script just not printing anything.
I have tried to do:
npm config set --ignore-scripts false
However that did not work.
npm config set ignore-scripts false
Was solved the issue.
npm run-script start worked for me (npm run is an alias to npm run-script as stated in doc but not sure why alias didnt work)
hope this helps people who are still facing the issue after setting ignore-script as false
On Windows you can also edit directly a file on the following location
C:\Users\[Your username]\.npmrc
and set ignore-scripts=false

Why does NodeJS require me to use the full directory for downloaded modules?

For something like Express for example, which does not come with Node by default. I have to use var express = require('C:/Users/User/node_modules/express'); instead of just var express = require('express');. I notice the modules which come by default such as http aren't in the same location as the ones I install. So what do I need to do in order to not have to write the whole directory. If it makes any difference I keep all my Node projects in C:/Node/, not the default one.
This is happening because you probably don't have node modules installed locally. For that you need a package.json file which you can get by running
npm init
This will ask you some questions about your project and will set up node locally. A package.json file will be created which should look something like this (without dependencies).
{
"name": "express-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "Link to your repository"
},
"author": "",
"license": "ISC",
"dependencies": {
"bcrypt": "^1.0.2",
"body-parser": "^1.17.2",
"chalk": "^2.0.1",
"compression": "^1.7.0",
"cookie-parser": "^1.4.3",
"cors": "^2.8.4",
"express": "^4.15.3",
"glob": "^7.1.2",
"moment": "^2.18.1",
"mongoose": "^4.11.3",
"morgan": "^1.8.2",
"passport": "^0.3.2",
"path": "^0.12.7",
"yargs": "^8.0.2"
}
}
You can then add the node modules you want by putting them in dependencies and running
npm install
If you want to add node modules from commond line you can use
npm install package-name --save

How does express know to run "server.js"?

I cracked open an experimental express project I hadn't touched for a couple of months, and I tried to trace through how everything works to refresh my understanding.
What confuses is me is that my express app is run from a file called server.js, but that is not specified anywhere in my package.json, nor is there any reference to such a filename (like as a default) in the node_modules folder for express. It works though, unless I rename the file (e.g. server_.js). I have no scripts setup in package.json. Whatever I specify for "main" in package.json seems to have no effect.
So how does npm start know to run the app from server.js?
{
"name": "my thing",
"version": "0.0.1",
"description": "This is my thing.",
"main": "index.js",
"scripts": {
"test": "test"
},
"repository": {
"type": "git",
"url": "my-thing"
},
"author": "Faust",
"license": "ISC",
"dependencies": {
"babel-core": "^6.25.0",
"babel-loader": "^7.1.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"material-ui": "^1.0.0-beta.4",
"material-ui-icons": "^1.0.0-alpha.19",
"express": "^4.15.4",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-redux": "^5.0.5",
"react-router": "^4.1.2",
"react-router-dom": "^4.1.2",
"redux": "^3.7.2",
"webpack": "^3.3.0"
}
}
ls of the root:
data/ entry.jsx node_modules/ npm-debug.log package.json public/ server.js src/ webpack.config.js
From the official NPM docs -
npm start runs an arbitrary command specified in the package's "start" property of its "scripts" object. If no "start" property is specified on the "scripts" object, it will run node server.js.
Read more here.

ember/npm addon with dependencies/ devDependencies

I have created an ember addon which relies on gulp derived packages to build, so in the addon it has the following in package.json.
When the addon is included in the main application, the build fails due to the various gulp modules being missing. The addon is in the devDependencies section of the main application.
The addon also builds into the main application when it is in through npm link. My question is how should the addon dependencies be handled so the main application builds without a local copy of the module?
Update: I think the problem is that the package does a gulp build after the postinstall which elevates the gulp devDependencies into real dependencies. Is this correct?
Addon JSON file
{
"name": "My Addon",
"version": "0.0.0",
"description": "The default blueprint for ember-cli addons.",
"directories": {
"doc": "doc",
"test": "tests"
},
"scripts": {
"build": "ember build",
"start": "ember server",
"test": "ember try:each",
"postinstall": "gulp build && bower install"
},
"repository": {
"type": "git",
"url": "git://github.com/myaddon.git"
},
"engines": {
"node": ">= 0.12.0"
},
"author": "",
"license": "MIT",
"devDependencies": {
"bootstrap": "^4.0.0-alpha.5",
"broccoli-asset-rev": "^2.4.5",
"broccoli-funnel": "^1.0.9",
"ember-ajax": "^2.4.1",
// more ember modules
"find-root": "^0.1.1",
"font-awesome": "^4.7.0",
"glob": "^4.5.3",
"gulp": "^3.9.1",
"gulp-clean-css": "^2.2.1",
"gulp-concat": "^2.6.0",
"gulp-connect": "^2.2.0",
"gulp-filter": "^3.0.1",
"gulp-git": "^1.4.0",
"gulp-rename": "^1.2.2",
"gulp-sass": "^2.3.2",
"gulp-sourcemaps": "^1.5.2",
"gulp-task-loader": "^1.2.1",
"gulp-template": "^3.0.0",
"gulp-uglify": "^1.2.0",
"gulp-zip": "^3.0.2",
"lazypipe": "^1.0.1",
"loader.js": "^4.0.10",
"run-sequence": "^1.1.2"
},
"keywords": [
"ember-addon"
],
"dependencies": {
"ember-cli-babel": "^5.1.7"
},
"ember-addon": {
"configPath": "tests/dummy/config"
}
}
The addon's dependencies are needed to build application (that includes addon), should be listed in dependencies section. The devDependencies of a package that is included as dependency of another package, are ignored.
There is other solution to add packages into an application. You can create a blueprint in your addon that will be called every time an application build with it or install it.

Resources