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

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

Related

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

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

"Failed to load gRPC binary module" error when running a Sails.js application inside a Docker container

I have a local Docker developer environment to build a Sails.js application. This is what my Dockerfile looks like:
FROM node:8.12
LABEL Name=us.gcr.io/my-project/my-app Version=1.0.0
# Container configuration
RUN npm install -g sails#1.0.2 grunt#1.0.3 nodemon#1.18.4
WORKDIR /usr/src/app
COPY ./server/package.json ./package.json
RUN npm install
VOLUME /usr/src/app
EXPOSE 1337
This is what my docker-compose.yml file looks like:
version: '3.4'
services:
server:
image: us.gcr.io/my-project/my-app:latest
build: .
environment:
NODE_ENV: development
IS_DEV_MACHINE: "yes"
ports:
- 1338:1337 # HOST_PORT is 1339 to avoid conflicts with other Sails.js apps running on host
volumes:
- ./server:/usr/src/app
entrypoint: nodemon
mongodb:
image: mongo:4
ports:
- 27018:27017 # HOST_PORT is 27018 to avoid conflicts with other MongoDB databases running on host
volumes:
- ../database:/data/db
Normally, everything works fine however, I recently imported and initialised the #google-cloud/logging NPM package in my application and now, when I run docker-compose up, I get the following error:
server_1 | error: Bootstrap encountered an error: (see below)
server_1 | error: Failed to lift app: { Error: Failed to load gRPC binary module because it was not installed for the current system
server_1 | Expected directory: node-v57-linux-x64-musl
server_1 | Found: [node-v57-darwin-x64-unknown]
server_1 | This problem can often be fixed by running "npm rebuild" on the current system
server_1 | Original error: Cannot find module '/usr/src/app/node_modules/grpc/src/node/extension_binary/node-v57-linux-x64-musl/grpc_node.node'
server_1 | at Object.<anonymous> (/usr/src/app/node_modules/grpc/src/grpc_extension.js:53:17)
server_1 | at Module._compile (module.js:653:30)
server_1 | at Object.Module._extensions..js (module.js:664:10)
server_1 | at Module.load (module.js:566:32)
server_1 | at tryModuleLoad (module.js:506:12)
server_1 | at Function.Module._load (module.js:498:3)
server_1 | at Module.require (module.js:597:17)
server_1 | at require (internal/module.js:11:18)
server_1 | at Object.<anonymous> (/usr/src/app/node_modules/grpc/src/client_interceptors.js:145:12)
server_1 | at Module._compile (module.js:653:30)
server_1 | at Object.Module._extensions..js (module.js:664:10)
server_1 | at Module.load (module.js:566:32)
server_1 | at tryModuleLoad (module.js:506:12)
server_1 | at Function.Module._load (module.js:498:3)
server_1 | at Module.require (module.js:597:17)
server_1 | at require (internal/module.js:11:18) code: 'MODULE_NOT_FOUND' }
mongodb_1 | 2018-10-09T09:27:52.521+0000 I NETWORK [conn4] end connection 172.19.0.2:48730 (0 connections now open)
In the error above, "Bootstrap" is the bootstrap.js file in my Sails.js project that initialises #google-cloud/logging. This is how I am initialising the logger in bootstrap.js:
// Globally required packages
const { Logging } = require('#google-cloud/logging');
const logging = new Logging({ projectId: 'my-project' });
const logger = logging.log('test');
I just can't seem to figure out why this error is occurring. I even tried changing my base Docker image to the official Google App Engine Docker image (gcr.io/google-appengine/nodejs) and that did not help either. i can't find any solutions to this problem anywhere. Appreciate any help.
By any chance did you do a npm install on your local Mac (darwin) environment when it should have been done in the container (linux)? The grpc binary is for the wrong OS thus the error. This often happens with a local Mac running a linux Docker container.
Expected directory: node-v57-linux-x64-musl
Found: [node-v57-darwin-x64-unknown]
The solution would be to rm -fr node_modules and do npm install in the container.
Rebuild the app by the following command.
npm rebuild --target=8.1.0 --target_platform=linux --target_arch=x64 --target_libc=musl
It looks like the project is having difficulty finding dependencies such as the gRPC binary module (repaired with npm install grpc) or perhaps where they are currently located - more info here

Can node.js ignore a local node_modules directory and only use global modules?

Can node.js be configured to only use a globally-installed modules and ignore a local node_modules directory?
For our node.js app (currently node.js 8.10.0), we build a Docker image where the required modules are installed globally, in a /node_modules folder, with the environment set to NODE_PATH=/node_modules. This works for production deployment.
For local development, we run the same Docker image, but mount the local development files at /app. This allows any locally changed files to be used by the image.
This works, until a developer runs npm install on their host system, and creates a node_modules directory. This is mounted at /app/node_modules. node examines this folder on startup, and starts complaining about missing binaries:
kumascript_1 | ## There is an issue with `node-fibers` ##
kumascript_1 | `/app/node_modules/fibers/bin/linux-x64-57/fibers.node` is missing.
kumascript_1 |
kumascript_1 | Try running this to fix the issue: /usr/local/bin/node /app/node_modules/fibers/build
kumascript_1 | /app/node_modules/fibers/fibers.js:20
kumascript_1 | throw new Error('Missing binary. See message above.');
kumascript_1 | ^
kumascript_1 |
kumascript_1 | Error: Missing binary. See message above.
kumascript_1 | at Object.<anonymous> (/app/node_modules/fibers/fibers.js:20:8)
kumascript_1 | at Module._compile (module.js:652:30)
kumascript_1 | at Object.Module._extensions..js (module.js:663:10)
kumascript_1 | at Module.load (module.js:565:32)
kumascript_1 | at tryModuleLoad (module.js:505:12)
kumascript_1 | at Function.Module._load (module.js:497:3)
kumascript_1 | at Module.require (module.js:596:17)
kumascript_1 | at require (internal/module.js:11:18)
kumascript_1 | at Object.<anonymous> (/app/lib/kumascript/templates.js:11:13)
kumascript_1 | at Module._compile (module.js:652:30)
If there was a way to tell node to ignore /app/node_modules, then a developer can do what they want with npm install on the host system, and the Docker container would continue running as expected.

Resources