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

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

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

How to schedule an adonisjs command with plesk scheduler?

I have this created command called 'newsletter'. When I call 'adonis newsletter' on local, it works just fine. But when I try to run with scheduler on plesk with 'cd httpdocs; node ace newsletter', it was completed with this error:
/var/www/vhosts/mydomain.com/httpdocs/node_modules/#adonisjs/ignitor/src/Ignitor/index.js:286
async _bootProviders () {
^^^^^^^^^^^^^^
SyntaxError: Unexpected identifier
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:44...
anyone know what is wrong? when i tried 'cd httpdocs; adonis newsletter' it gaves error too, it said that command not found.. my node version is 14
It worked when I use this command :
cd httpdocs; /opt/plesk/node/v16.13.1/bin/node ace newsletter;

Strapi develop script not working with PM2

I am trying to run Strapi in development mode with pm2 by using this command:
pm2 start npm --name myprojectname -- run develop
Unfortunately, I get the following error
0|edtech-a | SyntaxError: Unexpected token ':'
0|edtech-a | at wrapSafe (internal/modules/cjs/loader.js:979:16)
0|edtech-a | at Module._compile (internal/modules/cjs/loader.js:1027:27)
0|edtech-a | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
0|edtech-a | at Module.load (internal/modules/cjs/loader.js:928:32)
0|edtech-a | at Function.Module._load (internal/modules/cjs/loader.js:769:14)
0|edtech-a | at Object.<anonymous> (C:\Users\dimit\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:33:23)
0|edtech-a | at Module._compile (internal/modules/cjs/loader.js:1063:30)
0|edtech-a | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
0|edtech-a | at Module.load (internal/modules/cjs/loader.js:928:32)
0|edtech-a | at Function.Module._load (internal/modules/cjs/loader.js:769:14)
PM2 version is 4.5.1
NodeJS version is 14.15.4
NPM version is 6.13.2
Strapi version is 3.1.0-alpha.5
I get the same error when I try to run Strapi in development mode through an ecosystem.config.json file as well.
Has somebody faced this issue, if yes, how can I solve it?
Yeah, I encountered some problems myself and decided to go for a workaround:
Create a script with the commands you would type normally:
touch strapi.sh
Type in your desired commands:
nano strapi.sh
cd my-strapi-project
npm run develop
Close and save (Crtl+x then type "y" and press enter).
Now just start that file with pm2
pm2 start strapi.sh
Check if everything works fine
pm2 logs
Thats it.
Can you try with this:
pm2 start npm --name myprojectname --interpreter bash -- run develop
UPDATED
for yarn
pm2 start yarn --name myprojectname --interpreter bash -- run develop

Run native Nodejs in AS400 / iSeries

I'm trying to run Node.js on AS/400 server in order to use Node.js toolkit for IBM i.
I have installed Node v6.14.4 and NPM 3.10.10 and I'm following this documentation to test node.js: https://developer.ibm.com/articles/i-native-js-app-ibmi-with-nodejs/#access-ibm-i-native-objects
I created the sample javascript file and when I run (from PASE terminal), I get this error:
node /home/njs/sample.js
/sample.js:1
(function (exports, require, module, __filename, __dirname) { #����ï¿
½ï¿½ï¿½K���M È ï¿½ï¿½#����� ]^
SyntaxError: Invalid or unexpected token
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.runMain (module.js:611:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:160:9)
I supposed there is a problem with npm and I tried with a very simple js file (an only one console.log) and I get the same error.
I have solved my issue. It was because an enconding problem.
I was creating javascript files with EDTF on AS/400 environment and that was a problem. I created a new file with notepad and upload by Navigator for i and works properly.

Unexpected token import when trying to use pm2 on my react app digitalocean droplet

I am trying to host my app on DigitalOcean and getting it running with pm2 but run into this error:
/home/bcavenagh/social/src/index.js:1
(function (exports, require, module, __filename, __dirname) { import React from 'react';
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Object.<anonymous> (/usr/lib/node_modules/pm2/lib/ProcessContainerFork.js:27:21)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
I can get everything to run when using npm start but it doesnt work for pm2. In npm I am running from the ~/social folder but for pm2 I cd into ~/social/src and run:
pm2 start index.js
How do I get past this error?
You must compile/build your application, if not done so.
It will create a build folder (assuming you are using default configs with create-react-app), then you must point pm2 to the appropriate file (bundle.js or whatever you have) in that folder.
PM2 also supports running npm start command now. Checkout this question. What i usually do is, write a sh file, which updates code, does npm install and then at last runs pm2 command, for all deployments, which is similar to this answer in the previous link.

Resources