I'm using msvc and have nodejs tools setup in it. Fairly new to node.js but all the other npm packages i've simply installed via command line or through nodejs tools and they have worked. AppJS however gives me the error when I call require('appjs').
throw new Error('AppJS requires Node is run with the --harmony command
line)
Anyone know how to fix this? I get this error even when calling my script from command line doing
node --harmony app.js
Actual code
var serialPortLib = require("serialport");
var appjs = require('appjs');
var serialPort = new serialPortLib.SerialPort("COM13",{
baudrate : 250000,
parser : serialPortLib.parsers.readline('\n')
});
serialPort.on('open', function () { console.log('open'); serialPort.write("Sup!\n");});
serialPort.on('data',function(data){ console.log(data);})
Related
Using the following tracing enabling script from OpenTelemetry docs:
const opentelemetry = require("#opentelemetry/sdk-node");
const { getNodeAutoInstrumentations } = require("#opentelemetry/auto-instrumentations-node");
const { diag, DiagConsoleLogger, DiagLogLevel } = require('#opentelemetry/api');
// For troubleshooting, set the log level to DiagLogLevel.DEBUG
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);
const sdk = new opentelemetry.NodeSDK({
traceExporter: new opentelemetry.tracing.ConsoleSpanExporter(),
instrumentations: [getNodeAutoInstrumentations()]
});
sdk.start()
running my Next.js server as I thought is required, I get an error:
$ node --require './tracing/opentelemetry.js' ./node_modules/next/dist/bin/next start -p 3000
No modules instrumentation has been defined, nothing will be patched
#opentelemetry/instrumentation-grpc Module #grpc/grpc-js has been loaded before #opentelemetry/instrumentation-grpc so it might not work, please initialize it before requiring #grpc/grpc-js
Exporter "otlp" requested through environment variable is unavailable.
/mnt/vol/.local/share/pnpm/global/5/.pnpm/next#12.1.5_zpnidt7m3osuk7shl3s4oenomq/node_modules/next/dist/lib/get-project-dir.js:40
const realDir = _fs.default.realpathSync.native(resolvedDir);
^
TypeError: _fs.default.realpathSync.native is not a function
at Object.getProjectDir (/mnt/vol/.local/share/pnpm/global/5/.pnpm/next#12.1.5_zpnidt7m3osuk7shl3s4oenomq/node_modules/next/dist/lib/get-project-dir.js:40:50)
at nextStart (/mnt/vol/.local/share/pnpm/global/5/.pnpm/next#12.1.5_zpnidt7m3osuk7shl3s4oenomq/node_modules/next/dist/cli/next-start.js:80:37)
at /mnt/vol/.local/share/pnpm/global/5/.pnpm/next#12.1.5_zpnidt7m3osuk7shl3s4oenomq/node_modules/next/dist/bin/next:141:34
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Node.js v17.8.0
Now this can be simplified to a minimal reproduction as follows. This has the fs.realpathSync.native function:
$ node -e 'console.log(require("fs").realpathSync)'
[Function: realpathSync] { native: [Function (anonymous)] }
This doesn't have fs.realpathSync.native:
$ node --require ./tracing/opentelemetry.js -e 'console.log(require("fs").realpathSync)'
No modules instrumentation has been defined, nothing will be patched
#opentelemetry/instrumentation-grpc Module #grpc/grpc-js has been loaded before #opentelemetry/instrumentation-grpc so it might not work, please initialize it before requiring #grpc/grpc-js
[Function (anonymous)]
Exporter "otlp" requested through environment variable is unavailable.
My Node's --require is working correctly (noop.js is an empty file):
$ node --require ./tracing/noop.js -e 'console.log(require("fs").realpathSync)'
[Function: realpathSync] { native: [Function (anonymous)] }
Why would the OpenTelemetry setup script break the fs module?
$ node --version
v17.8.0
//package.json dependencies
"#opentelemetry/api": "^1.3.0",
"#opentelemetry/auto-instrumentations-node": "^0.35.0",
"#opentelemetry/sdk-node": "^0.34.0",
$ uname -a
Linux code-server 5.15.0-1025-oracle #31~20.04.2-Ubuntu SMP Tue Nov 29 13:01:56 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux
Does my ARM machine have something to do with it?
I can reproduce the same on x86_64 on https://replit.com/#JakubKoralewski/opentelemetry-repro with the same behavior.
The reason this error occurs is due to a bug in #opentelemetry/instrumentation-fs introduced as a new dependency to #opentelemetry/auto-instrumentations-node in PR #981 which got released with version 0.34.0. The issue was reported but at the time of writing is still open. However, as also already linked above a PR to address the issue is being reviewed.
Fow now, I see three ways to address the problem:
As suggested in a comment above downgrade #opentelemetry/auto-instrumentations-node to next lower version 0.33.1.
Disable the file system instrumentation when configuring the node instrumentation. For that simply replace getNodeAutoInstrumentations() with getNodeAutoInstrumentations({ '#opentelemetry/instrumentation-fs': { enabled: false } }) in your code. Given that your project is in Next.js and you likely have little file system activity aside from maybe public files this is likely the best option for now.
Remove #opentelemetry/auto-instrumentations-node altogether and simply instrument the libraries you actually use. Using the auto instrumentation for Node.js pulls in a lot of transitive dependencies. Say you have a Next.js app, connect to a Postgres database and use winston for logging your instrumentation setup could look something like this:
const sdk = new opentelemetry.NodeSDK({
traceExporter: new opentelemetry.tracing.ConsoleSpanExporter(),
instrumentations: [
// new FsInstrumentation(), TODO: re-enable once bug is fixed
new HttpInstrumentation(),
new PgInstrumentation(),
new WinstonInstrumentation(),
]
});
I am trying to publish npm package, when i am install the package globally and try to run the cli command i get this errors:
/.nvm/versions/node/v0.12.2/bin/myPack: line 1: use strict: command not found
/.nvm/versions/node/v0.12.2/bin/myPack: line 3: syntax error near unexpected token `('
/.nvm/versions/node/v0.12.2/bin/myPack: line 3: `var _commandLineArgs = require('command-line-args');'
The top of the file that the error refer to:
'use strict';
var _commandLineArgs = require('command-line-args');
var _commandLineArgs2 = _interopRequireDefault(_commandLineArgs);
The package.json bin section:
"bin": {
"myPack": "dist/myPack.js"
}
When i am running this in my local development this works well, what is the problem?
Your script should start with a shebang line, otherwise it will be executed as a shell script (hence the errors).
Add this as first line to dist/myPack.js:
#!/usr/bin/env node
I'm trying to execute a simple command using shelljs in nwjs like this :
main.js :
var shell = require("shelljs");
var output = shell.exec("bash ./test.sh",{silent:true,async:false}).output;
console.log(output);
test.sh :
echo "Hey there"
When I run the above file in nodejs like this
node main.js
It works without any problems. But when I try to run the above code using nwjs(assuming we have the basic project structure setup with the index.html and main.js), it gives me an error.
[23874:1031/211359:INFO:CONSOLE(191)] ""shell.js: internal error"", source: node_modules/shelljs/src/common.js (191)
[23874:1031/211359:INFO:CONSOLE(192)] ""Error: ENOENT: no such file or directory, open '/tmp/shelljs_b656f0ddaa7c3b096e97'\n at Error (native)\n at Object.fs.openSync (fs.js:540:18)\n at Object.fs.readFileSync (fs.js:392:15)\n at execSync (node_modules/shelljs/src/exec.js:109:24)\n at Object._exec (node_modules/shelljs/src/exec.js:214:12)\n at Object.exec (node_modules/shelljs/src/common.js:182:23)\n at file://main.js:33:16"", source: node_modules/shelljs/src/common.js (192)
I just want to know if there is any work around or solution to execute the code. Help is appreciated.
Thank you.
Use full path to test.sh:
var shell = require("shelljs");
var output = shell.exec("bash /path/to/test.sh",{silent:true,async:false}).output;
console.log(output);
Looks like shelljs searching file in: /tmp/shelljs_b656f0ddaa7c3b096e97
Where you place test.sh? Near nwjs? How you run code? From devtools? From project? From packed project?
Also, why you need shelljs? Nwjs already have internall API to work with shell:
var nwGui = require('nw.gui')
, nwShell = nwGui.Shell
, child_process = require('child_process')
, exec = child_process.exec
, execSync = child_process.execSync
, execFile = child_process.execFile
, execFileSync = child_process.execFileSync
;
var output = execSync("bash /path/to/test.sh");
console.log(output);
https://github.com/nwjs/nw.js/wiki/shell
I'm automating Chrome on Windows 8.1 with JavaScript using Selenium's WebDriverJS. I downloaded a copy of the ChromeDriver and Selenium Standalone Server jar file and placed in E:\Selenium directory. I started Selenium Standalone Server and tried to run my javascript code written in BrowserTest.js file with Node command prompt as
E:\Selenium> Node BrowserTest.js
the BrowserTest.js:
var driver = require("selenium-webdriver");
function createDriver() {
var driver = new driver.Builder()
.usingServer('http://localhost:4444/wd/hub')
.withCapabilities(driver.Capabilities.chrome())
.build();
driver.manage().timeouts().setScriptTimeout(10000);
return driver;
}
var driver = createDriver();
driver.get("http://www.google.com");
driver.getTitle().then(function (title) {
console.log(title);
});
driver.quit();
But it throws error as:
fs.js:500 return binding.open(pathModule._makeLong(path),
stringToFlags(flags), mode);
^ Error: ENOENT, no such file or directory 'E:\Selenium\webdriver\logging.js'
at Error (native)
at Object.fs.openSync (fs.js:500:18)
at Object.fs.readFileSync (fs.js:352:15)
at Object.Context.closure.goog.retrieveAndExecModule_ (E:\Selenium\node_modules\selenium-webdriver\_base.js:129:23)
at <anonymous>:1:6
at Object.exports.runInContext (vm.js:64:17)
at Context.closure.closure.vm.createContext.CLOSURE_IMPORT_SCRIPT (E:\Selenium\node_modules\selenium-webdriver\_base.js:101:12)
at Object.goog.importScript_ (E:\Selenium\node_modules\selenium-webdriver\lib\goog\base.js:873:9)
at Object.goog.importModule_ (E:\Selenium\node_modules\selenium-webdriver\lib\goog\base.js:894:14)
at Object.goog.writeScripts_ (E:\Selenium\node_modules\selenium-webdriver\lib\goog\base.js:1251:16)
Update
try changing the selenium-webdriver version to 2.46.1, it has been pushed to npm and in it, the bug has been fixed.
like #simon said, this bug is already been reported in github,
for now, one hack has been suggested as solution in it's comments,
go to node_modules\selenium-webdriver\_base.js, add below line between line 100 and line 101( as first line of if block):
opt_srcText = opt_srcText.replace(/\\/g,'/');
it fixed the problem for me.
There appears to be a bug in v2.46.0 of Selenium on windows.
It has just been fixed in 2.46.1, so if you update it should solve your problem
Problem was solved by updating to version - 2.46.1
I have a net.connect script that I am attempting to install as a service on a Windows XP machine.
The application installs correctly using NSSM prior to my attempt to include forever-monitor.
It also works correctly when launching the forever-monitor script manually.
I have attempted to install forever-monitor local to the app and globally but either way produces the same result.
The service installs and then immediately pauses. It will not start.
Can anyone see what I am doing wrong?
The Forever-Monitor code:
// nstream.js
var forever = require('forever-monitor');
var child = new (forever.Monitor)('nstream.0.0.3.js', {
silent: true,
});
child.on('exit', function () {
});
child.start();
Issuing the NSSM command from CMD prompt:
c:\avl\src\nssm.exe install "Test" "c:\program files\nodejs\node.exe" "c:\avl\bin\nstream\nstream.js"
The solution, it turns out, is to add the sourceDir option:
// nstream.js
var forever = require('forever-monitor');
var child = new (forever.Monitor)('nstream.0.0.3.js', {
silent: true,
sourceDir: 'c:/avl/bin/nstream'
});
child.on('exit', function () {
});
child.start();