Apex Up - Error: Cannot find module 'debug' - node.js

The error persists after I CLI enter up stack delete and also when I CLI enter up in an alternative directory that I know worked previously. Error also persists if I revert inconsequential changes to a prior working state.
Changing the name field in the up.json file results in a successful deploy in the alternate directory! But something about deploying with the same alternate name from my problem directory causes the issue again.
npm i -S debug does not help.
Has anyone else experienced and resolved this problem somehow?
UPDATE: Getting closer. By commenting things in and out I've got the error
"Error: Cannot find module './src/resolvers'"
From line:
var resolvers_1 = require("./src/resolvers");
Changing to:
var resolvers_1 = require("./resolvers");
fixes the single import issue, but not the remaining...
I'd move the index.js file to the src directory and keep a flat file structure... but I have complex reasons I can't do that.
"apex logs" of issue:
Aug 31st 05:58:27pm INFO staging 88776d6 initializing
Aug 31st 05:58:27pm INFO staging 88776d6 starting app: PORT=33461 command=node dist/index.js
Aug 31st 05:58:27pm INFO staging 88776d6 started app
Aug 31st 05:58:27pm INFO staging 88776d6 waiting for app to listen on PORT
Aug 31st 05:58:28pm ERRO staging 88776d6 module.js:549
Aug 31st 05:58:28pm ERRO staging 88776d6 throw err;
Aug 31st 05:58:28pm ERRO staging 88776d6 ^
Aug 31st 05:58:28pm ERRO staging 88776d6
Aug 31st 05:58:28pm ERRO staging 88776d6 Error: Cannot find module 'debug'
Aug 31st 05:58:28pm ERRO staging 88776d6 at Function.Module._resolveFilename (module.js:547:15)
Aug 31st 05:58:28pm ERRO staging 88776d6 at Function.Module._load (module.js:474:25)
Aug 31st 05:58:28pm ERRO staging 88776d6 at Module.require (module.js:596:17)
Aug 31st 05:58:28pm ERRO staging 88776d6 at require (internal/module.js:11:18)
Aug 31st 05:58:28pm ERRO staging 88776d6 at Object. (/var/task/node_modules/finalhandler/index.js:14:13)
Aug 31st 05:58:28pm ERRO staging 88776d6 at Module._compile (module.js:652:30)
Aug 31st 05:58:28pm ERRO staging 88776d6 at Object.Module._extensions..js (module.js:663:10)
Aug 31st 05:58:28pm ERRO staging 88776d6 at Module.load (module.js:565:32)
Aug 31st 05:58:28pm ERRO staging 88776d6 at tryModuleLoad (module.js:505:12)
Aug 31st 05:58:28pm ERRO staging 88776d6 at Function.Module._load (module.js:497:3)
Aug 31st 05:58:42pm FATA staging 88776d6 error creating handler: waiting for http://127.0.0.1:33461 to be in listening state: timed out after 15s: name=clowdfuncserver type=server
Aug 31st 05:58:42pm INFO 2018-09-01T00:58:42.959Z 22adf73a-ad82-11e8-9c6c-79de5ffabc3f Error: read ECONNRESET
at _errnoException (util.js:1022:11)
at Pipe.onread (net.js:628:25)

Despite additional issues blocking me, this webpack configuration worked for me:
// webpack.config.js
module.exports = {
entry: "./src/index.ts",
module: {
rules: [
{
exclude: [/node_modules/],
test: /\.tsx?$/,
use: "ts-loader"
},
{
include: /node_modules/,
test: /\.mjs$/,
type: "javascript/auto"
}
]
},
node: false,
output: {
filename: "index.js",
path: path.join(__dirname, "dist")
},
resolve: {
extensions: [".tsx", ".ts", ".js", ".mjs"]
},
target: "node"
};

Related

Core Node.js module "fs" Not Found when #fastify/static deployed on render.com

It is my understanding that the core modules, like "fs" are part of the node.js build, and no special configuration is needed to make them available for importing, so I'm at a loss as to how "fs" could be missing when running on render.com. I have no problems building or running in development mode locally. And the service deploys and builds perfectly on render.com, but running fails with:
Jan 31 01:13:22 PM ==> Starting service with 'node index.js'
Jan 31 01:13:23 PM internal/modules/cjs/loader.js:888
Jan 31 01:13:23 PM throw err;
Jan 31 01:13:23 PM ^
Jan 31 01:13:23 PM
Jan 31 01:13:23 PM **Error: Cannot find module 'node:fs'**
Jan 31 01:13:23 PM Require stack:
Jan 31 01:13:23 PM - /opt/render/project/src/node_modules/#fastify/send/lib/SendStream.js
Jan 31 01:13:23 PM - /opt/render/project/src/node_modules/#fastify/send/index.js
Jan 31 01:13:23 PM - /opt/render/project/src/node_modules/#fastify/static/index.js
Jan 31 01:13:23 PM - /opt/render/project/src/index.js
Jan 31 01:13:23 PM at Function.Module._resolveFilename (internal/modules/cjs/loader.js:885:15)
Jan 31 01:13:23 PM at Function.Module._load (internal/modules/cjs/loader.js:730:27)
Jan 31 01:13:23 PM at Module.require (internal/modules/cjs/loader.js:957:19)
Jan 31 01:13:23 PM at require (internal/modules/cjs/helpers.js:88:18)
Jan 31 01:13:23 PM at Object.<anonymous> (/opt/render/project/src/node_modules/#fastify/send/lib/SendStream.js:10:12)
Jan 31 01:13:23 PM at Module._compile (internal/modules/cjs/loader.js:1068:30)
Jan 31 01:13:23 PM at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
Jan 31 01:13:23 PM at Module.load (internal/modules/cjs/loader.js:933:32)
Jan 31 01:13:23 PM at Function.Module._load (internal/modules/cjs/loader.js:774:14)
Jan 31 01:13:23 PM at Module.require (internal/modules/cjs/loader.js:957:19) {
Jan 31 01:13:23 PM code: 'MODULE_NOT_FOUND',
Jan 31 01:13:23 PM requireStack: [
Jan 31 01:13:23 PM '/opt/render/project/src/node_modules/#fastify/send/lib/SendStream.js',
Jan 31 01:13:23 PM '/opt/render/project/src/node_modules/#fastify/send/index.js',
Jan 31 01:13:23 PM '/opt/render/project/src/node_modules/#fastify/static/index.js',
Jan 31 01:13:23 PM '/opt/render/project/src/index.js'
Jan 31 01:13:23 PM ]
Jan 31 01:13:23 PM }
The service was running merrily along until I deployed a new version today that requires the #fastify/static package, like this:
fastify.register(require('#fastify/static'), { root: path.join(__dirname,'public'), prefix:'/public/' })
I never import "fs" directly, but #fastify/static apparently does, like this:
const statSync = require('fs').statSync
I tried importing fs explicitly before importing #fastify, but the error doesn't change. Webpack is not involved. I've tried building using both npm and yarn, no difference - not that building should affect core modules. Is there some critical environmental setup I have neglected to do on Render.com?
Ronnie's comment (thks!) made me start wondering if my assumption that "node:fs" was the same as "fs" was correct. It was not. Render.com defaults to node.js version 14.17.0. The "node:" module reference syntax was not added until a later version.
The solution was to request node version 16.0.0 on render.com using an environment variable containing the version string, and it fixed the error.
The details for specifying the version on render.com is at https://render.com/docs/node-version
An explanation of the core modules syntax is at https://nodejs.org/api/modules.html

Binary from app using winston package don't run as linux service

I have a very simple node js application that uses the npm Winston package.
The code is only a loop printing date using the Winston package The app runs just fine. I created a binary using
npm run build
or
npx pkg -t linux,macos,win . --out-path dist
and it also runs just fine. the problem is that when I run it as a service using the file
[Unit]
Description=Cryptween daemon service
After=systend-user-sessions.service
[Service]
Type=simple
WorkingDirectory=$CRYPTWEEN_BIN_DIR
ExecStart=$CRYPTWEEN_BIN_DIR/cryptween-daemon-linux
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=CttWBot_Console
[Install]
WantedBy=multi-user.target
I get the error
cryptween.service - Cryptween daemon service
Loaded: loaded (/etc/systemd/system/cryptween.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2022-03-24 10:54:45 -03; 1s ago
Process: 213784 ExecStart=/opt/cryptween/bin/cryptween-daemon-linux (code=exited, status=1/FAILURE)
Main PID: 213784 (code=exited, status=1/FAILURE)
mar 24 10:54:45 gintama CttWBot_Console[213784]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
mar 24 10:54:45 gintama CttWBot_Console[213784]: at Module.load (node:internal/modules/cjs/loader:981:32)
mar 24 10:54:45 gintama CttWBot_Console[213784]: at Function.Module._load (node:internal/modules/cjs/loader:822:12)
mar 24 10:54:45 gintama CttWBot_Console[213784]: at Module.require (node:internal/modules/cjs/loader:1005:19)
mar 24 10:54:45 gintama CttWBot_Console[213784]: at Module.require (pkg/prelude/bootstrap.js:1719:31)
mar 24 10:54:45 gintama CttWBot_Console[213784]: at require (node:internal/modules/cjs/helpers:102:18)
mar 24 10:54:45 gintama CttWBot_Console[213784]: at Object.<anonymous> (/snapshot/test-error-daemon/src/config/winston-logger.js:2:16)
mar 24 10:54:45 gintama CttWBot_Console[213784]: at Module._compile (pkg/prelude/bootstrap.js:1794:22)
mar 24 10:54:45 gintama systemd[1]: cryptween.service: Main process exited, code=exited, status=1/FAILURE
mar 24 10:54:45 gintama systemd[1]: cryptween.service: Failed with result 'exit-code'.
Here is the code:
code
I am using ubuntu 20.04
Thank you in advance

Lighthouse reporting is failing in Jenkins with below error

Fri, 28 May 2021 09:27:18 GMT ChromeLauncher Waiting for browser.............................................................................................
Fri, 28 May 2021 09:27:19 GMT ChromeLauncher Waiting for browser...............................................................................................
Fri, 28 May 2021 09:27:19 GMT ChromeLauncher Waiting for browser.................................................................................................
Fri, 28 May 2021 09:27:20 GMT ChromeLauncher Waiting for browser...................................................................................................
Fri, 28 May 2021 09:27:20 GMT ChromeLauncher Waiting for browser.....................................................................................................
Fri, 28 May 2021 09:27:21 GMT ChromeLauncher Waiting for browser.......................................................................................................
Fri, 28 May 2021 09:27:21 GMT ChromeLauncher:error connect ECONNREFUSED 127.0.0.1:36157
Fri, 28 May 2021 09:27:21 GMT ChromeLauncher:error Logging contents of /tmp/lighthouse.mOZ6RIf/chrome-err.log
Fri, 28 May 2021 09:27:21 GMT ChromeLauncher:error Fontconfig warning: "/etc/fonts/fonts.conf", line 86: unknown element "blank"
Inconsistency detected by ld.so: ../elf/dl-tls.c: 488: _dl_allocate_tls_init: Assertion `listp->slotinfo[cnt].gen <= GL(dl_tls_generation)' failed!
Unable to connect to Chrome
370/0: Lighthouse analysis FAILED for https://website.com/en/....
rm: no such file or directory: report/lighthouse/website/en....report.json
/var/lib/jenkins/workspace/project/node_modules/lighthouse-batch/index.js:219
const score = toScore(summary.detail.performance)
TypeError: Cannot read property 'performance' of undefined
at checkBudgets (/var/lib/jenkins/workspace/project/node_modules/lighthouse-batch/index.js:219:42)
at /var/lib/jenkins/workspace/project/node_modules/lighthouse-batch/index.js:67:20
at Array.map (<anonymous>)
at execute (/var/lib/jenkins/workspace/project/node_modules/lighthouse-batch/index.js:39:38)
at Object.<anonymous> (/var/lib/jenkins/workspace/project/node_modules/lighthouse-batch/run.js:28:1)
at Module._compile (internal/modules/cjs/loader.js:1068:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
at Module.load (internal/modules/cjs/loader.js:933:32)
at Function.Module._load (internal/modules/cjs/loader.js:774:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Lighthouse_Reports#1.0.0 lighthouse: `lighthouse-batch -f sites.txt -p --config-path=config.js -h --performance 75 --score 70 --no-report –chrome-flags='–headless','--no-sandbox'`
npm ERR! Exit status 1
I'm running this report for 900+ page urls.
As the logs tell, ChromeLauncher is refusing connection to Jenkins. You might want to check if Jenkins is allowed to access this running service.
This can also happen if your ChromeLauncher is not running in headless mode, or multiple instances of ChromeLauncher are running, and no available ports for it are left.
You can try adding the following to you ChromeLauncher launch configs. In fact, you should mention these.
chromeOptions = {
chromeFlags: ["--disable-gpu", "--headless", "--enable-logging"]
}
Find more details to this here.
As an alternative, you can consider running Lighthouse in a Docker instead, to isolate it from Jenkins. This way, you can scan your project, generate HTML reports and publish it back to Jenkins.
You can follow the approach mentioned here.

Server.listen() in node gives " Error [ERR_SERVER_ALREADY_LISTEN]: Listen method has been called more than once without closing."

Apologies if some aspects of the question here are unclear as I am new to node & javascript. Please ask for further details
I have a node application that is connected to firebase using socketio. When the application is deployed on heroku, I get the following error:
Error [ERR_SERVER_ALREADY_LISTEN]: Listen method has been called more than once without closing.
Nov 01 19:57:38 app/web.1: at Server.listen (net.js:1446:11)
Nov 01 19:57:38 app/web.1: at exports.default (/app/dist/server.js:8226:11)
Nov 01 19:57:38 app/web.1: at Object.<anonymous> (/app/dist/server.js:191:21)
Nov 01 19:57:38 app/web.1: at __webpack_require__ (/app/dist/server.js:20:30)
Nov 01 19:57:38 app/web.1: at Object.<anonymous> (/app/dist/server.js:47:19)
Nov 01 19:57:38 app/web.1: at __webpack_require__ (/app/dist/server.js:20:30)
Nov 01 19:57:38 app/web.1: at /app/dist/server.js:40:18
Nov 01 19:57:38 app/web.1: at Object.<anonymous> (/app/dist/server.js:43:10)
Nov 01 19:57:38 app/web.1: at Module._compile (module.js:641:30)
Nov 01 19:57:38 app/web.1: at Object.Module._extensions..js (module.js:652:10)
Nov 01 19:57:38 app/web.1: /app/dist/server.js:212
Nov 01 19:57:38 app/web.1: throw error;
The description of the error is on this link :
https://nodejs.org/api/all.html#errors_err_server_already_listen
The listening code on my server.js is as shown:
const server = http.createServer(app).listen(port)
Any idea why this error is occurring? Should I close the server if the listen fails. If yes, how can I do it?
Thank you.
My bad. I got confused as the error was not occurring on my mac. The answer is in the error itself. The error was occurring as the listen method was being called twice. The second call was in some other module.

Cannot find module on start of new Nodejitsu deployment

I have a node application that runs locally and when deploying to Nodejitsu via jitsu deploy, the CLI reports a successful deployment. However, when actually logging in to look at the application via the web based interface and attempting to activate the snapshot, the start fails with the following error:-
err Wed, 05 Nov 2014 14:10:37 GMT
err Wed, 05 Nov 2014 14:10:37 GMT module.js:340
err Wed, 05 Nov 2014 14:10:37 GMT throw err;
err Wed, 05 Nov 2014 14:10:37 GMT Error: Cannot find module '/opt/run/snapshot/package/js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
err Wed, 05 Nov 2014 14:10:37 GMT ^
The trouble I am having, is the vagueness of the error. What is '/opt/run/snapshot/package/js'? Is there a way of getting more detail out of Nodejitsu so I can see what maybe causing the problem? Is this something anyone else has had?
I can return to this question with more information if requested.
Help, as always, appreciated.
I solved this. The problem was in my packages.json I had the following:-
"scripts": {
"start": "js server",
"postinstall": "bower install",
"test": "make test-cov"
},
js is of course not recognised by Nodejitsu on run. I found, by changing it to:-
"scripts": {
"start": "node server.js"
},
I had no problems.
A note to future Nodejitsu deployers, postinstall runs locally -- not on the server; therefore remove bower_components from your .gitignore if you need bower components on nodejitsu.
Hope this helps any adventurers who wander by.

Resources