node Issue in Creating demo project using react_on_rails gem - node.js

I am trying to follow this tutorial to create a dummy project using gem react_on_rails
I guess I have followed every step of the tutorial but on the last step where we have to run the project a node js related error is popping up.
I even updated my node version on the system, still facing the same issue
Error
foreman start -f Procfile.dev
22:30:58 web.1 | started with pid 5370
22:30:58 client.1 | started with pid 5371
22:30:59 client.1 | (in /home/projects/test-react-on-rails)
22:31:00 web.1 | => Booting Puma
22:31:00 web.1 | => Rails 5.1.2 application starting in development on http://localhost:3000
22:31:00 web.1 | => Run `rails server -h` for more startup options
22:31:00 web.1 | Puma starting in single mode...
22:31:00 web.1 | * Version 3.9.1 (ruby 2.4.0-p0), codename: Private Caller
22:31:00 web.1 | * Min threads: 5, max threads: 5
22:31:00 web.1 | * Environment: development
22:31:00 web.1 | * Listening on tcp://localhost:3000
22:31:00 web.1 | Use Ctrl-C to stop
22:31:01 client.1 | yarn run v0.27.5
22:31:01 client.1 | $ NODE_ENV=development webpack -w --config webpack.config.js
22:31:01 client.1 | /home/projects/test-react-on-rails/client/webpack.config.js:6
22:31:01 client.1 | const {resolve } = require('path');
22:31:01 client.1 | ^
22:31:01 client.1 |
22:31:01 client.1 | SyntaxError: Unexpected token {
22:31:01 client.1 | at exports.runInThisContext (vm.js:53:16)
22:31:01 client.1 | at Module._compile (module.js:373:25)
22:31:01 client.1 | at Object.Module._extensions..js (module.js:416:10)
22:31:01 client.1 | at Module.load (module.js:343:32)
22:31:01 client.1 | at Function.Module._load (module.js:300:12)
22:31:01 client.1 | at Module.require (module.js:353:17)
22:31:01 client.1 | at require (internal/module.js:12:17)
22:31:01 client.1 | at requireConfig (/home/shubhangi/projects/test-react-on-rails/client/node_modules/webpack/bin/convert-argv.js:96:18)
22:31:01 client.1 | at /home/projects/test-react-on-rails/client/node_modules/webpack/bin/convert-argv.js:109:17
22:31:01 client.1 | at Array.forEach (native)
22:31:01 client.1 | error Command failed with exit code 1.
22:31:01 client.1 | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
22:31:02 client.1 | exited with code 1
22:31:02 system | sending SIGTERM to all processes
22:31:02 web.1 | - Gracefully stopping, waiting for requests to finish
22:31:02 web.1 | === puma shutdown: 2017-07-27 22:31:02 +0530 ===
22:31:02 web.1 | - Goodbye!
22:31:02 web.1 | Exiting
22:31:02 web.1 | exited with code 0

You're trying to use object destructuring, which was first supported in Node version 6, and is not available in Node 4.
You should upgrade your Node version, especially since version 4 is no longer actively maintained, which means that only critical fixes are applied, until it reaches the end of life (for details see LTS schedule).
If you still have to use Node 4, you cannot use object destructuring and have to change the line to:
const resolve = require('path').resolve;
Another possibility would be to transpile the unsupported features with Babel, but that seems a little heavy handed for a config.

Related

create-react-app react-scripts start - ajv-errors: NOT SUPPORTED: option jsonPointers. Deprecated jsPropertySyntax can be used instead

Seeing this error after coming back to a project after a few weeks. Changed/updated nothing, everything was working fine last time I had this laptop open. The following error happens in a container when I'm running docker-compose up.
yarn run v1.22.17
client | $ react-scripts start
client | NOT SUPPORTED: option jsonPointers. Deprecated jsPropertySyntax can be used instead.
client | /app/node_modules/ajv-errors/index.js:4
client | if (!ajv._opts.allErrors) throw new Error('ajv-errors: Ajv option allErrors must be true');
client | ^
client |
client | TypeError: Cannot read properties of undefined (reading 'allErrors')
client | at module.exports (/app/node_modules/ajv-errors/index.js:4:18)
client | at Object.<anonymous> (/app/node_modules/webpack-dev-server/node_modules/schema-utils/src/validateOptions.js:22:1)
client | at Module._compile (node:internal/modules/cjs/loader:1103:14)
client | at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
client | at Module.load (node:internal/modules/cjs/loader:981:32)
client | at Function.Module._load (node:internal/modules/cjs/loader:822:12)
client | at Module.require (node:internal/modules/cjs/loader:1005:19)
client | at require (node:internal/modules/cjs/helpers:102:18)
client | at Object.<anonymous> (/app/node_modules/webpack-dev-server/node_modules/schema-utils/src/index.js:7:25)
client | at Module._compile (node:internal/modules/cjs/loader:1103:14)
client | error Command failed with exit code 1.
client | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
client exited with code 1
So posting my own question I changed how I was looking at the problem.
I came across this question/answer AJV and ajv-formats latest must be broken in React
I found the answer from #Tsar Bomba about installing
npm install ajv#7.2.3 ajv-errors#2.0.1 ajv-formats#2.1.1 --save
Worked for me and I was able to serve my project again
The following also worked for me.
npm install ajv#7.2.3 ajv-errors#2.0.1 ajv-formats#2.1.1 --save

PM2 crashes while using ES modules in nodejs

Ive enabled ES modules in pacakage.json with this key value pair "type": "module" i dont have to use the 'experimental' flag with the latest version of node
when i run pm2 start app.js --watch the app crashes with the error message
0|app | Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only file and data URLs are supported by the default ESM loader
0|app | at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:781:11)
0|app | at Loader.resolve (internal/modules/esm/loader.js:85:40)
0|app | at Loader.getModuleJob (internal/modules/esm/loader.js:229:28)
0|app | at Loader.import (internal/modules/esm/loader.js:164:28)
0|app | at importModuleDynamically (internal/modules/cjs/loader.js:1194:27)
0|app | at exports.importModuleDynamicallyCallback (internal/process/esm_loader.js:30:14)
0|app | at Object.<anonymous> (C:\Users\username\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:29:24)
0|app | at Module._compile (internal/modules/cjs/loader.js:1251:30)
0|app | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1272:10)
0|app | at Module.load (internal/modules/cjs/loader.js:1100:32) {
0|app | code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
0|app | }
the app works perfectly fine without pm2. im guessing pm2 does not support ESM yet!
any workarounds or am i missing some configurations?
Try to pass harmony as node arguments as it will enable es6 features in pm2 process.
pm2 start my_app.js --watch --node-args="--harmony"
If you are on windows 10
pm2 not working with esm on windows 10, there are no workarounds!

"SyntaxError: Invalid or unexpected token" when running node-red using PM2 on Win ES 7

Node-red version: 0.19.5
PM2 version: 3.2.3
OS: Windows Embedded Standard 7 (Running on ICO300, with 8gb of RAM)
Steps to reproduce
Install node-red and pm2 on Windows ES 7
Run node red through pm2: pm2 start node-red
Check node-red logs: pm2 logs node-red
Result
I got the following error:
0|node-red | SyntaxError: Invalid or unexpected token
0|node-red | at new Script (vm.js:79:7)
0|node-red | at createScript (vm.js:251:10)
0|node-red | at Object.runInThisContext (vm.js:303:10)
0|node-red | at Module._compile (internal/modules/cjs/loader.js:656:28)
0|node-red | at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
0|node-red | at Module.load (internal/modules/cjs/loader.js:598:32)
0|node-red | at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
0|node-red | at Function.Module._load (internal/modules/cjs/loader.js:529:3)
0|node-red | at Object.<anonymous> (c:\Users\Administrator\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:27:21)
0|node-red | at Module._compile (internal/modules/cjs/loader.js:688:30)
0|node-red | C:\USERS\ADMINISTRATOR\APPDATA\ROAMING\NPM\NODE-RED.CMD:1
0|node-red | (function (exports, require, module, __filename, __dirname) { #IFEXIST "%~dp0\node.exe" (
and node-red does not run.
Running node-red directly from CMD can be done normally (except that after 1 hour it usually crashes (cause discussed here, still unsolved), that's why as a workaround I want to use PM2 to auto-restart it.)
On Windows, the node-red.cmd is not a valid, you have to run directly the Node.js command instead:
pm2 start C:\Users\<USER-NAME>\AppData\Roaming\npm\node_modules\node-red\red.js

Localhost POST request for GroupMe Bot

I'm trying to test a GroupMe bot that I made using Node.js. I'm using the Example Bot by GroupMe. After running foreman start and
curl -X POST -d \cool guy\ localhost:5000 (from a similar question), I get the error curl: (1) Protocol "guy http" not supported or disabled in libcurl. I tried wrapping the message in double quotes, but that only resulted in a syntax error. How can I fix this?
Edit:
I tried
$ curl -X POST -d "cool guy" localhost:5000
and got the following error from foreman:
22:04:16 web.1 | started with pid 5788
22:04:32 web.1 | undefined:1
22:04:32 web.1 | cool guy
22:04:32 web.1 | ^
22:04:32 web.1 | SyntaxError: Unexpected token c
22:04:32 web.1 | at Object.parse (native)
22:04:32 web.1 | at Object.respond (C:\Users\Nicky\Documents\GitHub\groupme-jarvis\bot.js:11:24)
22:04:32 web.1 | at apply (C:\Users\Nicky\Documents\GitHub\groupme-jarvis\node_modules\director\lib\director\router.js:448:19)
22:04:32 web.1 | at _every (C:\Users\Nicky\Documents\GitHub\groupme-jarvis\node_modules\director\lib\director\router.js:30:9)
22:04:32 web.1 | at Router.invoke (C:\Users\Nicky\Documents\GitHub\groupme-jarvis\node_modules\director\lib\director\router.js:454:5)
22:04:32 web.1 | at IncomingMessage.parseAndInvoke (C:\Users\Nicky\Documents\GitHub\groupme-jarvis\node_modules\director\lib\director\http\index.js:175:10)
22:04:32 web.1 | at IncomingMessage.g (events.js:199:16)
22:04:32 web.1 | at IncomingMessage.emit (events.js:104:17)
22:04:32 web.1 | at _stream_readable.js:908:16
22:04:32 web.1 | at process._tickCallback (node.js:355:11)
22:04:32 web.1 | exited with code 1
22:04:32 system | sending SIGKILL to all processes
Add http:// in front of localhost. Libcurl, the library that curl uses, supports many different protocols. Curl is correctly assuming http, but seems to be have a bug.
Edit: after reading the question again, I see that curl was compiled without http support. If you compiled it yourself, make sure to enable http support. If you installed it using a distributions package manager, try reinstalling.

Port in use when launching Node.js app with Heroku Foreman

I am trying to deploy my node.js app to heroku but when I try to launch it locally using foreman I am getting Error: listen EADDRINUSE. I have run a netstat and grepped for the port nothing else is using it and the server starts without issue when running directly as a node http server.
The app I am trying to deploy is using mongo and redis I am not sure if these components will effect the server starting with Foreman. Does anyone have any suggestions on areas I could look at for potential bugs?
foreman start
01:37:18 web.1 | started with pid 1835
01:37:18 web.1 | /usr/local/foreman/lib/foreman/process.rb:66: warning: Insecure world writable dir /usr/local in PATH, mode 040777
01:37:19 web.1 | events.js:72
01:37:19 web.1 | throw er; // Unhandled 'error' event
01:37:19 web.1 | ^
01:37:19 web.1 | Error: listen EADDRINUSE
01:37:19 web.1 | at errnoException (net.js:863:11)
01:37:19 web.1 | at Server._listen2 (net.js:1008:14)
01:37:19 web.1 | at listen (net.js:1030:10)
01:37:19 web.1 | at Server.listen (net.js:1096:5)
01:37:19 web.1 | at Function.app.listen (/Users/craig/Documents/Sandboxes /xxx/node_modules/express/lib/application.js:535:24)
01:37:19 web.1 | at Object.<anonymous> (/Users/craig/Documents/Sandboxes/xxx/web.js:25:5)
01:37:19 web.1 | at Module._compile (module.js:456:26)
01:37:19 web.1 | at Object.Module._extensions..js (module.js:474:10)
01:37:19 web.1 | at Module.load (module.js:356:32)
01:37:19 web.1 | at Function.Module._load (module.js:312:12)
01:37:19 web.1 | exited with code 8
01:37:19 system | sending SIGTERM to all processes
SIGTERM received
Thanks.
--Additional information--
The procfile just has one entry:
web: node web.js
and I have set the listener up as follows:
var port = process.env.PORT || 5000;
app.listen(port, function() {
console.log("Listening on " + port);
});
I just ran into this on OS X. It looks like foreman picks port 5000 by default, which seems to conflict with Bonjour/mDNS/UPNP services. (From what I've read. I haven't taken the time to pick out which it is.)
However, you can change the port that foreman uses in two ways: specify the port on the command line or create a .foreman file with the port number specified there.
Good luck and happy coding!
I had the same issue, Error: listen EADDRINUSE means that a Node server is already running.
Check that you are not running a Node server for the same project locally. If you are working on a GitHub synced project locally (on port 5000 for instance) which is tied to Heroku you cannot run a local Node server for that project as the port will be in use twice.
I was actually running a Node server on a project in a different Terminal window and didn't notice immediately.

Resources