hello i got problem when deploying adonisjs + nextjs + reactjs in cpanel. i got the log error like this
events.js:291
throw er; // Unhandled 'error' event
^
Error: spawn /opt/alt/alt-nodejs12/root/usr/bin/node EAGAIN
at Process.ChildProcess._handle.onexit (internal/child_process.js:268:19)
at onErrorNT (internal/child_process.js:470:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:274:12)
at onErrorNT (internal/child_process.js:470:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
errno: 'EAGAIN',
code: 'EAGAIN',
syscall: 'spawn /opt/alt/alt-nodejs12/root/usr/bin/node',
path: '/opt/alt/alt-nodejs12/root/usr/bin/node',
spawnargs: [
'/home/test123/nodevenv/repositories/testproject/12/lib/node_modules/jest-worker/build/workers/processChild.js'
]
}
my server.js
'use strict'
const { Ignitor } = require('#adonisjs/ignitor')
new Ignitor(require('#adonisjs/fold'))
.appRoot(__dirname)
.fireHttpServer()
.catch(console.error)
my next.config.js
'use strict'
const next = require('next')
const { withPlugins } = require('next-compose-plugins')
const withOffline = require('next-offline')
require('dotenv').config()
const nextWithOfflineConfig = {
dontAutoRegisterSw: false,
generateInDevMode: false,
workboxOpts: {
swDest: './next/.next/service-worker.js',
runtimeCaching: [
{
urlPattern: /^https?.*/,
handler: 'NetworkFirst',
options: {
cacheName: 'https-calls',
networkTimeoutSeconds: 15,
expiration: {
maxEntries: 150,
maxAgeSeconds: 1 * 24 * 60 * 60, // 1 day
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
],
debug: false,
},
}
const nextEnv = {
env: {
APP_KEY: process.env.APP_KEY,
}
}
module.exports = withPlugins([
[withOffline, { nextWithOfflineConfig }],
[nextEnv]
])
package.json
"next": "^10.0.9",
"next-compose-plugins": "^2.2.1",
"next-offline": "^5.0.3",
"next-page-transitions": "^1.0.0-beta.2",
"next-pwa": "^5.2.21",
"react": "^17.0.2",
cpanel dependencies
node 12.22.9
npm 6.14.0
i already try
rm -rf node_modules
rm package-lock.json yarn.lock
npm cache clear --force
npm install
but still not solve the issue
any solutions?
I'm going to guess your server is running CloudLinux, as this is when this error usually comes up?
It's down to the limits on the number of processes and threads you can create inside an LVE. If you edit your next.conf.js and add the experimental section:
module.exports = {
experimental: {
workerThreads: false,
cpus: 4
}
};
This disables worker threads, and sets a CPU count of 4 so it limits the processes created - you might still need to adjust this depending on the limits inside the account you're running the build from.
You can read a bit more about it here in the blog I wrote after helping a customer with the same issue: https://kdaws.com/2022/10/fixing-next-js-error-spawn-errno-11-on-cpanel-and-plesk-with-cloudlinux/
Thanks,
Karl
Related
I have created a whatsapp bot which uses openai, whatsapp-web.js and nodejs.
While deploying it on vercel, I am facing following issues:
Error: Failed to launch the browser process!
[0212/144729.058867:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported.
These are the output that I am getting on deployment:
Running build in Washington, D.C., USA (East) – iad1
Cloning github.com/hritik2002/GitaGpt-Bot (Branch: main, Commit: 17356f1)
Previous build cache not available
Cloning completed: 401.653ms
Running "vercel build"
Vercel CLI 28.15.3
Running "install" command: `npm install`...
npm WARN deprecated puppeteer#13.7.0: < 18.1.0 is no longer supported
added 121 packages, and audited 122 packages in 6s
10 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
/vercel/path0/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:241
reject(new Error([
^
Error: Failed to launch the browser process!
[0212/144729.058867:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
at onClose (/vercel/path0/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:241:20)
at Interface.<anonymous> (/vercel/path0/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:231:68)
at Interface.emit (node:events:525:35)
at Interface.close (node:internal/readline/interface:536:10)
at Socket.onend (node:internal/readline/interface:262:10)
at Socket.emit (node:events:525:35)
at endReadableNT (node:internal/streams/readable:1359:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Node.js v18.12.1
Error: Command "node app.js" exited with 1
My package.json file:
{
"dependencies": {
"axios": "^0.26.1",
"qrcode-terminal": "^0.12.0",
"whatsapp-web.js": "^1.18.0"
}
}
My app.js code:
const qrcode = require("qrcode-terminal");
const { Client, LocalAuth, MessageMedia } = require("whatsapp-web.js");
const axios = require("axios");
async function QueryMessage(message) {
// performs certain task:
}
const client = new Client({
authStrategy: new LocalAuth(),
});
client.initialize();
client.on("qr", (qr) => {
qrcode.generate(qr, { small: true });
});
client.on("authenticated", () => {
console.log("AUTHENTICATED");
});
client.on("ready", () => {
console.log("Client is ready!");
});
const sendMessage = async (chat, message) => {
await chat.sendMessage(await QueryMessage(message));
};
//Replying Messages with image from url
client.on("message", async (message) => {
const chat = await message.getChat();
if (!chat.isGroup) {
sendMessage(chat, message.body);
}
});
I am new to Next JS.
I can't build my application locally. When I enter the npm run build command I get the following errors :
...
_currentUrl: 'http://localhost:3003/data/menus.json',
[Symbol(kCapture)]: false
},
response: undefined,
isAxiosError: true,
toJSON: [Function: toJSON]
}
Error: connect ECONNREFUSED 127.0.0.1:3003
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1148:16) {
errno: -4078,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3003,
config: {
url: 'http://localhost:3003/data/menus.json',
method: 'get',
headers: {
Accept: 'application/json, text/plain, */*',
'User-Agent': 'axios/0.21.4'
},
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 0,
adapter: [Function: httpAdapter],
...
Et à la fin du log
...
info - Generating static pages (771/771)
> Build error occurred
Error: Export encountered errors on following paths:
/ar
/ar/classic
/ar/minimal
/ar/standard
/ar/vintage
/de
/de/classic
/de/minimal
/de/standard
/de/vintage
/en
/en/classic
/en/minimal
/en/standard
/en/vintage
/es
/es/classic
/es/minimal
/es/standard
/es/vintage
/fr
/fr/classic
/fr/minimal
/fr/standard
/fr/vintage
/he
/he/classic
/he/minimal
/he/standard
/he/vintage
/zh
/zh/classic
/zh/minimal
/zh/standard
/zh/vintage
at C:\Users\PC\OneDrive\Documents\lab\samara\laravel\node_modules\next\dist\export\index.js:487:19
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async Span.traceAsyncFn (C:\Users\PC\OneDrive\Documents\lab\samara\laravel\node_modules\next\dist\telemetry\trace\trace.js:60:20)
at async C:\Users\PC\OneDrive\Documents\lab\samara\laravel\node_modules\next\dist\build\index.js:833:17
at async Span.traceAsyncFn (C:\Users\PC\OneDrive\Documents\lab\samara\laravel\node_modules\next\dist\telemetry\trace\trace.js:60:20)
at async C:\Users\PC\OneDrive\Documents\lab\samara\laravel\node_modules\next\dist\build\index.js:707:13
at async Span.traceAsyncFn (C:\Users\PC\OneDrive\Documents\lab\samara\laravel\node_modules\next\dist\telemetry\trace\trace.js:60:20)
at async Object.build [as default] (C:\Users\PC\OneDrive\Documents\lab\samara\laravel\node_modules\next\dist\build\index.js:77:25)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed.
Exit code: 1
Command: C:\Program Files\nodejs\node.exe
Arguments: C:\Users\PC\.node\corepack\yarn\1.22.15\lib\cli.js build
Directory: C:\Users\PC\OneDrive\Documents\lab\samara\laravel\shop
Output:
info Visit https://yarnpkg.com/en/docs/cli/workspace for documentation about this command.
error Command failed with exit code 1.
The npm run dev command works without any problem. So locally the application has no problem. But when I go to production, I want to build I get these errors above.
Here is my server.js file:
// server.js
const { createServer } = require('http');
const { parse } = require('url');
const next = require('next');
const dev = process.env.NODE_ENV !== 'production';
const hostname = 'localhost';
const port = 3003;
// when using middleware `hostname` and `port` must be provided below
const app = next({ dev, hostname, port });
const handle = app.getRequestHandler();
app.prepare().then(() => {
createServer(async (req, res) => {
try {
// Be sure to pass `true` as the second argument to `url.parse`.
// This tells it to parse the query portion of the URL.
const parsedUrl = parse(req.url, true);
const { pathname, query } = parsedUrl;
if (pathname === '/a') {
await app.render(req, res, '/a', query);
} else if (pathname === '/b') {
await app.render(req, res, '/b', query);
} else {
await handle(req, res, parsedUrl);
}
} catch (err) {
console.error('Error occurred handling', req.url, err);
res.statusCode = 500;
res.end('internal server error');
}
}).listen(port, (err) => {
if (err) throw err;
console.log(`> Ready on http://${hostname}:${port}`);
});
});
And my package.json file
{
"name": "#samara/shop",
"version": "1.1.0",
"private": true,
"scripts": {
"dev": "next dev -p 3003",
"build": "next build",
"start": "NODE_ENV=production node server.js"
If you need another file to check let me know.
I don't know if it's the best way but in my case I run npm run dev then run npm run build and the error stops happening
then stop the dev and run npm run start
you can also add a try catch in the api call http://localhost:3003/data/menus.json
if you are calling in a getStaticProps function, you can in the catch set the revalidity to 1 second if you need to revalidate
This one is a duplicate of a:
ECONNREFUSED during 'next build'. Works fine with 'next dev'
The issue is explained quite well in this thread.
Essentially as the comment states:
You should not fetch an API route from getStaticProps...
Please check also Ciro Santilli answer, he gives more details to the issue
I have the following code that successfully uploads test.sspkg to my sharepoint app catalog. Now I'm trying to use sp-request to prove that it's actually there.
But I'm getting an ECONNREFUSED error.
Error message
This shows the error:
[14:24:15] INFO: Checking if file (test.sppkg) is checked out
[14:24:15] INFO: File checkout type: 0
[14:24:17] Published file 1482ms
[14:24:17] And we're done...
trying to retrieve: https://mytenant.sharepoint.com/sites/JJTest/_api/web/GetFileByServerRelativeUrl(#FileUrl)/$value?#FileUrl='%2Fsites%2FJJTest%2FAppCatalog%2Ftest.sppkg'
errored out
{ GotError: connect ECONNREFUSED 127.0.0.1:443
at onError (/src/myplugins/node_modules/got/dist/source/request-as-event-emitter.js:140:29)
at ClientRequest.request.on.error (/src/myplugins/node_modules/got/dist/source/request-as-event-emitter.js:157:17)
at ClientRequest.emit (events.js:203:15)
at ClientRequest.EventEmitter.emit (domain.js:448:20)
at ClientRequest.origin.emit.args (/src/myplugins/node_modules/#szmarczak/http-timer/dist/source/index.js:43:20)
at TLSSocket.socketErrorListener (_http_client.js:401:9)
at TLSSocket.emit (events.js:198:13)
at TLSSocket.EventEmitter.emit (domain.js:448:20)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1107:14) name: 'RequestError', code: 'ECONNREFUSED' }
Package
This is the node package I'm using to call the SP API:
"dependencies": {
"sp-request": "^3.0.0"
}
Code:
const sprequest = require('sp-request');
await new Promise((resolve, reject) => {
gulp
.src(folderLocation)
.pipe(
spsync({
username: uname,
password: pwd,
site: siteCatalogUrl + "/",
libraryPath: catalogName,
publish: true,
verbose: true
}))
.on("finish", () => {
var spr = sprequest.create({ username: uname, password: pwd });
//https://mytenant.sharepoint.com/sites/JJTest/_api/web/getFileByServerRelativeUrl('/sites/JJTest/AppCatalog/test.sppkg')
var filepath = `${siteCatalogUrl}/_api/web/GetFileByServerRelativeUrl(#FileUrl)/$value?#FileUrl='${encodeURIComponent("/sites/JJTest/AppCatalog/test.sppkg")}'`;
console.log('trying to retrieve: ' + filepath);
var retrieveFileUrl = filepath;
spr.get(filepath, {
encoding:null
})
.then(data => {
expect(fileContent.equals(data.body)).is.true;
resolve();
})
.catch(data => {
console.log('errored out')
console.log(data)
reject();
});
resolve();
});
});
What I've tried:
I have tried just copying parts of the output from my console directly into the browser. Specifically, this is the output i get from my debug print statement:
trying to retrieve: https://mytenant.sharepoint.com/sites/JJTest/_api/web/GetFileByServerRelativeUrl/(#FileUrl)/$value?#FileUrl='%2Fsites%2FJJTest%2FAppCatalog%2Ftest.sppkg'
errored out
Pasting this:
https://mytenant.sharepoint.com/sites/JJTest/_api/web/GetFileByServerRelativeUrl('/sites/JJTest/AppCatalog/test.sppkg')
into a browser as the URL works. It returns the details of the file to me.
Can you tell me where I've gone wrong? maybe the syntax of substituting the #FileUrl?
I am using gulp version 3.9.1. And I just did a install latest of chai and sp-request.
But tried changing the specific versions to:
"sp-request": "^2.1.3"
"gulp": "^3.9.1",
"gulp-spsync-creds": "2.3.8",
"chai": "3.5.0"
And now, it's happy! it worked!
I'm using the imageMagick subclass of graphicsmagick to alter ~7k png images. The function below gets about 2/3 of the way through and fails (see log).
Seems to be an issue where a socket is failing. How do I debug this?
A thought I have is to use the -limit method, but no dice...
Thanks in advance :)
Code:
// changing an image's resolution is the same thing as changing its DPI
export default async function changeScreenshotResolution(dimension) {
new Promise(() => {
try {
const screenshots = fs.readdirSync(path.join(__dirname, `../output/screenshots/${dimension}`), function(error) {if (error) console.log(error)});
screenshots.map(screenshot => {
try {
let readStream = fs.createReadStream(path.join(__dirname, `../output/screenshots/${dimension}/${screenshot}`));
let writeStream = fs.createWriteStream(path.join(__dirname, `../output/screenshots/${dimension}1/${screenshot}`));
im(readStream, screenshot)
.limit('memory', '32MB') // i tried variations of this but it made no difference
.units('PixelsPerInch')
.density(300,300)
.stream()
.pipe(writeStream)
console.log(screenshot);
} catch (error) {
console.log(`Error changing screenshot resolution: ${error}`);
}
})
} catch (error) {
console.log(`changeScreenshotResolution error: ${error}`);
}
})
};
Error: spawn convert EAGAIN
at Process.ChildProcess._handle.onexit (internal/child_process.js:268:19)
at onErrorNT (internal/child_process.js:468:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
errno: -35,
code: 'EAGAIN',
syscall: 'spawn convert',
path: 'convert',
spawnargs: [
'-density',
'300x300',
'/Users/daddy/Dev/scout/project-sunroof-scraping/output/screenshots/rect/6550 ARABIAN CIR.png',
'-units',
'PixelsPerInch',
'/Users/daddy/Dev/scout/project-sunroof-scraping/output/screenshots/rect1/6550 ARABIAN CIR.png'
]
}
events.js:292
throw er; // Unhandled 'error' event
^
Error: read ENOTCONN
at tryReadStart (net.js:571:20)
at Socket._read (net.js:582:5)
at Socket.Readable.read (_stream_readable.js:474:10)
at Socket.read (net.js:622:39)
at new Socket (net.js:374:12)
at Object.Socket (net.js:265:41)
at createSocket (internal/child_process.js:313:14)
at ChildProcess.spawn (internal/child_process.js:436:23)
at Object.spawn (child_process.js:548:9)
at spawn (/Users/daddy/Dev/scout/project-sunroof-scraping/node_modules/cross-spawn/index.js:17:18)
at gm._spawn (/Users/daddy/Dev/scout/project-sunroof-scraping/node_modules/gm/lib/command.js:224:14)
at /Users/daddy/Dev/scout/project-sunroof-scraping/node_modules/gm/lib/command.js:101:12
at series (/Users/daddy/Dev/scout/project-sunroof-scraping/node_modules/array-series/index.js:11:36)
at gm._preprocess (/Users/daddy/Dev/scout/project-sunroof-scraping/node_modules/gm/lib/command.js:177:5)
at gm.write (/Users/daddy/Dev/scout/project-sunroof-scraping/node_modules/gm/lib/command.js:99:10)
at /Users/daddy/Dev/scout/project-sunroof-scraping/modules/changeScreenshotDPI.js:18:26
Emitted 'error' event on Socket instance at:
at emitErrorNT (internal/streams/destroy.js:100:8)
at emitErrorCloseNT (internal/streams/destroy.js:68:3)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
errno: -57,
code: 'ENOTCONN',
syscall: 'read'
}
I have an exe and I want to run it from node.js, and pass an argument, except that it doesn't work..
var exec = require('child_process').execFile;
const fs = require('fs');
try {
if (fs.existsSync("./program/bin/Release/program.exe")) {
console.log("Exists")
} else {
console.log("Not Exists")
}
} catch(err) {
console.log(err)
}
setTimeout(function() {
exec('./program/bin/Release/program.exe manual', function(err, data) {
console.log(err)
console.log(data.toString());
});
}, 0);
It definitely exists as it prints exists, and I can run it from a cmd prompt giving manual as an argument. But through node.js it is not working. It comes back with
Error: spawn ./program/bin/Release/program.exe manual ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)
at onErrorNT (internal/child_process.js:456:16)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
errno: 'ENOENT',
code: 'ENOENT',
syscall: 'spawn ./program/bin/Release/program.exe manual',
path: './program/bin/Release/program.exe manual',
spawnargs: [],
cmd: './program/bin/Release/program.exe manual'
}
Does anyone know?
Thanks
Arguments should be passed as an array of strings as the second argument, like so:
exec('./program/bin/Release/program.exe', ['manual'], function(err, data) {
console.log(err)
console.log(data.toString());
});
https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback