node querystring not defined in script only - node.js

I can use querystring in node 4.2.6 from a script, but I can from a node prompt. Here's some proof.
I have the following script:
$ cat test.js
console.log(process.versions)
console.log(querystring)
And I get an error when I run it:
$ node test.js
{ http_parser: '2.5.0',
node: '4.2.6',
v8: '4.5.103.35',
uv: '1.8.0',
zlib: '1.2.8',
ares: '1.10.1-DEV',
icu: '56.1',
modules: '46',
openssl: '1.0.2e' }
/path/to/file/test.js:2
console.log(querystring)
^
ReferenceError: querystring is not defined
at Object.<anonymous> (/path/to/file/test.js:2:13)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:442:10)
at startup (node.js:136:18)
at node.js:966:3
But if I go into node on the command line, I don't get the error.
$ node
> console.log(process.versions)
{ http_parser: '2.5.0',
node: '4.2.6',
v8: '4.5.103.35',
uv: '1.8.0',
zlib: '1.2.8',
ares: '1.10.1-DEV',
icu: '56.1',
modules: '46',
openssl: '1.0.2e' }
undefined
> console.log(querystring)
{ unescapeBuffer: [Function],
unescape: [Function],
escape: [Function],
encode: [Function],
stringify: [Function],
decode: [Function],
parse: [Function] }
undefined
The console.log() is just for proof--I can't use querystring at all in a script. What could be wrong?

The node REPL (what you get when just typing the executable name (node)) automatically loads built-in modules as globals as they are accessed by name as a convenience. This is mentioned in the documentation here.
For scripts that you load with node foo.js you will need to require() modules manually to pull in what you actually need. For the querystring module, you would just need to do:
var querystring = require('querystring');
There is no need to npm install querystring as the module is built-in to node.

Related

electrode-server throwing hapi webpack error

I am trying run this app locally using the below run command, and I am getting errors with starting the electrode server. I am rather new to this so please let me know what information is necessary in order to diagnose my issue. Thank you in advance for any help.
Relevant Dependencies
"#walmart/electrode-ccm-client": "3.3.1",
"#walmart/electrode-quimby-client": "2.0.2",
"#walmart/electrode-ui-config": "3.8.2",
"#walmart/electrode-wml-app": "3.3.5",
"electrode-archetype-react-app": "6.5.4",
"hapi": "^17.0.0",
- Dev -
"#walmart/electrode-build-utils": "^1.1.0",
"electrode-archetype-react-app-dev": "6.5.4",
"webpack-bundle-analyzer": "^3.7.0"
Run command:
NODE_TLS_REJECT_UNAUTHORIZED=0 clap dev
Terminal output:
Starting Electrode webpack dev server
electrode-server caught an error while starting your server
failed registering your plugin 'webpackDevHapi' with module '"./dev-hapi.js"' from path: 'CWD/node_modules/electrode-archetype-react-app-dev/lib/dev-admin'
message: Invalid plugin options {
"__name": "webpackDevHapi",
"module": "./dev-hapi.js",
"requireFromPath": "CWD/node_modules/electrode-archetype-react-app-dev/lib/dev-admin"
}
[1] "attributes" is required
Suggestion to resolve the issue:
Please double check and verify your plugin 'webpackDevHapi'.
If you have followed this resolution step and you are still seeing an
error, please file an issue on the electrode-server repository
git+https://github.com/electrode-io/electrode-server.git
Error: Invalid plugin options {
"__name": "webpackDevHapi",
"module": "./dev-hapi.js",
"requireFromPath": "CWD/node_modules/electrode-archetype-react-app-dev/lib/dev-admin"
}
[1] "attributes" is required
at Object.exports.assert (CWD/node_modules/electrode-server/node_modules/hoek/lib/index.js:740:11)
at Object.exports.apply (CWD/node_modules/electrode-server/node_modules/hapi/lib/schema.js:17:10)
at module.exports.internals.Server.internals.Plugin.register (CWD/node_modules/electrode-server/node_modules/hapi/lib/plugin.js:216:25)
at CWD/node_modules/electrode-server/lib/electrode-server.js:238:16
at CWD/node_modules/electrode-server/lib/electrode-server.js:237:29
From previous event:
at registerPlugins (CWD/node_modules/electrode-server/lib/electrode-server.js:234:20)
From previous event:
at startElectrodeServer (CWD/node_modules/electrode-server/lib/electrode-server.js:294:6)
at CWD/node_modules/electrode-server/lib/electrode-server.js:365:14
From previous event:
at start (CWD/node_modules/electrode-server/lib/electrode-server.js:354:71)
at processImmediate (internal/timers.js:464:21)
From previous event:
at electrodeServer (CWD/node_modules/electrode-server/lib/electrode-server.js:412:6)
at Object.<anonymous> (CWD/node_modules/electrode-archetype-react-app-dev/lib/dev-admin/dev-server.js:23:3)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)
at internal/main/run_main_module.js:17:47
Unhandled rejection Error: Invalid plugin options {
"__name": "webpackDevHapi",
"module": "./dev-hapi.js",
"requireFromPath": "CWD/node_modules/electrode-archetype-react-app-dev/lib/dev-admin"
}
[1] "attributes" is required
at Object.exports.assert (CWD/node_modules/electrode-server/node_modules/hoek/lib/index.js:740:11)
at Object.exports.apply (CWD/node_modules/electrode-server/node_modules/hapi/lib/schema.js:17:10)
at module.exports.internals.Server.internals.Plugin.register (CWD/node_modules/electrode-server/node_modules/hapi/lib/plugin.js:216:25)
at CWD/node_modules/electrode-server/lib/electrode-server.js:238:16
at CWD/node_modules/electrode-server/lib/electrode-server.js:237:29
From previous event:
at registerPlugins (CWD/node_modules/electrode-server/lib/electrode-server.js:234:20)
From previous event:
at startElectrodeServer (CWD/node_modules/electrode-server/lib/electrode-server.js:294:6)
at CWD/node_modules/electrode-server/lib/electrode-server.js:365:14
From previous event:
at start (CWD/node_modules/electrode-server/lib/electrode-server.js:354:71)
at processImmediate (internal/timers.js:464:21)
From previous event:
at electrodeServer (CWD/node_modules/electrode-server/lib/electrode-server.js:412:6)
at Object.<anonymous> (CWD/node_modules/electrode-archetype-react-app-dev/lib/dev-admin/dev-server.js:23:3)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)
at internal/main/run_main_module.js:17:47
Electrode webpack dev server exited code 0 - signal null

can you help? Error: Cannot find module 'react-dev-utils/WatchMissingNodeModulesPlugin'

Error: Cannot find module 'react-dev-utils/WatchMissingNodeModulesPlugin'
Require stack:
- C:\Users\stromboli\IdeaProjects\projects-ui\config\webpack.config.js
- C:\Users\stromboli\IdeaProjects\projects-ui\scripts\start.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1014:15)
at Function.Module._load (internal/modules/cjs/loader.js:884:27)
at Module.require (internal/modules/cjs/loader.js:1074:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (C:\Users\stromboli\IdeaProjects\projects-ui\config\webpack.config.js:18:39)
at Module._compile (internal/modules/cjs/loader.js:1185:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1205:10)
at Module.load (internal/modules/cjs/loader.js:1034:32)
at Function.Module._load (internal/modules/cjs/loader.js:923:14)
at Module.require (internal/modules/cjs/loader.js:1074:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (C:\Users\stromboli\IdeaProjects\projects-ui\scripts\start.js:32:23)
at Module._compile (internal/modules/cjs/loader.js:1185:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1205:10)
at Module.load (internal/modules/cjs/loader.js:1034:32)
at Function.Module._load (internal/modules/cjs/loader.js:923:14) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\stromboli\\IdeaProjects\\projects-ui\\config\\webpack.config.js',
'C:\\Users\\stromboli\\IdeaProjects\\projects-ui\\scripts\\start.js'
]
}
No matter what I do localhost won't open and I get this error. The github solutions shown didn't work either, how can I fix it I'm about to go crazy.
npm ls react-dev-utils
`-- react-dev-utils#12.0.1
In your config find webpack.config.dev.js and remove the following:
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
module.exports = {
// ...
plugins: [
// If you require a missing module and then `npm install` it, you still have
// to restart the development server for Webpack to discover it. This plugin
// makes the discovery automatic so you don't have to restart.
// See https://github.com/facebook/create-react-app/issues/186
new WatchMissingNodeModulesPlugin(paths.appNodeModules),
]
}

Algorithm "brotliCompress" is not found in "zlib"

I have installed compression-webpack-plugin using this link and added Compression plugin in plugin section of webpack.config.js file as suggested here
When I run npm run build I am getting an error
Algorithm "brotliCompress" is not found in "zlib"
I am using node v8.11.3.
Here is the full error
C:\Projects\ProjName\FrontEnd\node_modules\webpack-cli\bin\cli.js:93
throw err;
^
Error: Algorithm "brotliCompress" is not found in "zlib"
at new CompressionPlugin (C:\Projects\ProjName\FrontEnd\node_modules\compression-webpack-plugin\dist\index.js:171:15)
at Object. (C:\Projects\ProjName\FrontEnd\webpack\webpack.config.prod.js:67:5)
at Module._compile (C:\Projects\ProjName\FrontEnd\node_modules\v8-compile-cache\v8-compile-cache.js:192:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (C:\Projects\ProjName\FrontEnd\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
at WEBPACK_OPTIONS (C:\Projects\ProjName\FrontEnd\node_modules\webpack-cli\bin\utils\convert-argv.js:114:13)
at requireConfig (C:\Projects\ProjName\FrontEnd\node_modules\webpack-cli\bin\utils\convert-argv.js:116:6)
at C:\Projects\ProjName\FrontEnd\node_modules\webpack-cli\bin\utils\convert-argv.js:123:17
at Array.forEach ()
at module.exports (C:\Projects\ProjName\FrontEnd\node_modules\webpack-cli\bin\utils\convert-argv.js:121:15)
at yargs.parse (C:\Projects\ProjName\FrontEnd\node_modules\webpack-cli\bin\cli.js:71:45)
at Object.parse (C:\Projects\ProjName\FrontEnd\node_modules\webpack-cli\node_modules\yargs\yargs.js:576:18)
at C:\Projects\ProjName\FrontEnd\node_modules\webpack-cli\bin\cli.js:49:8
at Object. (C:\Projects\ProjName\FrontEnd\node_modules\webpack-cli\bin\cli.js:366:3)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object. (C:\Projects\ProjName\FrontEnd\node_modules\webpack\bin\webpack.js:156:2)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3 npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! ProjName#1.0.0 build: npm run buildsprite && webpack --config ./webpack/webpack.config.prod.js --colors npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the ProjName#1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely
additional logging output above.
npm ERR! A complete log of this run can be found in: npm ERR!
C:\Users\2048537\AppData\Roaming\npm-cache_logs\2021-12-29T09_59_46_237Z-debug.log
This is how I injected the plugin
new CompressionPlugin({
filename: "[path][base].br",
algorithm: "brotliCompress",
test: /\.(js|css|html|svg)$/,
compressionOptions: {
params: {
[zlib.constants.BROTLI_PARAM_QUALITY]: 11,
},
},
threshold: 10240,
minRatio: 0.8,
deleteOriginalAssets: false,
}),
Looks like webpack team needs to update https://webpack.js.org/plugins/compression-webpack-plugin/#using-brotli link.
I replace plugin code as below as below
new BrotliGzip({
asset: '[file].br[query]',
algorithm: "brotli",
test: /\.(js|css|html|svg)$/,
threshold: 10240,
minRatio: 0.8,
quality: 11
}),
where BrotliGzip is defined as
const BrotliGzip = require("brotli-gzip-webpack-plugin");
then it worked.

Error: Cannot find module 'selenium-selenium'

Versions are:
nvm --version 0.35.3
npm -v: 6.14.8
node -v: v14.10.0
important package.json parts:
{
"main": "index.js",
"scripts": {
"start": "./node_modules/mocha/bin/mocha index.js",
"install": "bash install.sh",
"clear": "rm -R -f node_modules && rm package-lock.json"
},
"dependencies": {
"chromedriver": "^84.0.1",
"dotenv": "^8.2.0",
"mocha": "^8.1.2",
"selenium-webdriver": "^4.0.0-alpha.7"
}
}
index.js:
require('dotenv').config()
const password = process.env.PASSWORD;
const selenium = require('selenium-selenium');
const chrome = require('selenium-selenium/chrome');
const chromedriver = require('chromedriver');
describe('Init driver and login', () => {
//... Should run through as an empty test but does not
});
and the error I'm getting when I'm running mocha index.js or npm run start:
Error: Cannot find module 'selenium-selenium'
Require stack:
- /home/mts/Desktop/projects/selenium/index.js
- /home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/esm-utils.js
- /home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/mocha.js
- /home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/cli/one-and-dones.js
- /home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/cli/options.js
- /home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/bin/mocha
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:893:15)
at Function.Module._load (internal/modules/cjs/loader.js:743:27)
at Module.require (internal/modules/cjs/loader.js:965:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/home/mts/Desktop/projects/selenium-moco/index.js:11:18)
at Module._compile (internal/modules/cjs/loader.js:1076:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
at Module.load (internal/modules/cjs/loader.js:941:32)
at Function.Module._load (internal/modules/cjs/loader.js:782:14)
at Module.require (internal/modules/cjs/loader.js:965:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.exports.requireOrImport (/home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/esm-utils.js:20:12)
at Object.exports.loadFilesAsync (/home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/esm-utils.js:33:34)
at Mocha.loadFilesAsync (/home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/mocha.js:427:19)
at singleRun (/home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/cli/run-helpers.js:156:15)
at exports.runMocha (/home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/cli/run-helpers.js:225:10)
at Object.exports.handler (/home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/lib/cli/run.js:366:11)
at /home/mts/.nvm/versions/node/v14.10.0/lib/node_modules/mocha/node_modules/yargs/lib/command.js:241:49
As simple as possible, but the module is not found - why? Should I try the lowest versions possible? I wanted to avoid the compatibility hell so I used only the newest versions available.
I think you use incorrect package name in your code - selenium-selenium. This package doesn't available on npmjs.org.
Try change this lines in our code:
const selenium = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');

How can I debug my koa program with IDEA?

I need your help.
I can run my program but I can't use debug tool. When I click debug button it shows that there is something wrong. I can't figure it out. I use IDEA to debug my koa program.
If I need do something before debugging?
Debugger listening on ws://127.0.0.1:14967/66cdd084-feab-406a-924f-42d8d3c41141
For help, see: https://nodejs.org/en/docs/inspector
Error in JetBrains node debug connector: Error: spawnSync C:/Program Files/nodejs/node.exe ENOENT
at Object.spawnSync (internal/child_process.js:1041:20)
at spawnSync (child_process.js:616:24)
at execFileSync (child_process.js:643:15)
at Object.<anonymous> (C:\Users\dvdx\AppData\Local\Temp\debugConnector.202.6397.94.js:36:3)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at Module._preloadModules (internal/modules/cjs/loader.js:1298:12) {
errno: 'ENOENT',
code: 'ENOENT',
syscall: 'spawnSync C:/Program Files/nodejs/node.exe',
path: 'C:/Program Files/nodejs/node.exe',
spawnargs: [
'C:\\Users\\dvdx\\AppData\\Local\\Temp\\debugConnector.202.6397.94.js'
],
error: [Circular],
status: null,
signal: null,
output: null,
pid: 0,
stdout: null,
stderr: null
}

Resources