After compiling a basic code to open a default browser, there's a warning.
After running , it product this error.
I am searching on pkg issues about this problem, an currently no solution binding with pkg compiler.
I am sharing my solution to this problem, so may be others save their time.
To solve the problem, after compiling a js code.
let's say you output the executable file to /folder_name/ .
copy node_modules/opn/xdg-open to /folder_name
and run it like on *nix: /folder_name $ ./execfile .
Related
I am wondering can I compile a nodejs file from mytestfile.js to mytestfile so I can run it on linux like this ./mytestfile ?
Thank you for your time
Add the following line to the very top of the .js file:
#!/usr/bin/env node
You might have to change the file permission and make it an executable:
chmod +x mytestfile.js
Example mytestfile.js:
#!/usr/bin/env node
// Grab provided args.
const [,, ...args] = process.argv
// Print hello world provided args
console.log(`Hello World ${args}`)
There are a couple of very good and well maintained packages that do that.
I can't tell you which is better. Try both pkg and nexe
The closest you might get to acheiving your goal is to create a self-executing Javascript bytecode wrapper.
A project that does this is pkg
It somehow creates a self-contained binary executable from Javascript, including module dependencies and asset files and produces a self-contained executable.
Installation and use is easy:
$ npm install -g pkg
$ pkg index.js -o my-program
$ ./my-program
My understanding is that this binary contains nodejs bytecode. It also appears that you can cross-compile.
I'm writing a project using Haskell, stack and hint. I'm using hint to interpret a user-supplied module. The catch is that this module uses types and functions from a dependency. When I run my program using stack exec, everything works fine. However, when I install my program (using stack install --local-bin-path bin) and try to run the executable generated, the GHC interpreter fails with an error: Could not find module <module>. This is because (I think) it can't find the files needed for it to interpret source code referring to this dependency. Does anyone know how to fix this? I'm using Windows 10.
I've uploaded a minimal not-working example at https://github.com/bradrn/stack-overflow-hint-dependencies. It works fine if you do stack exec stack-overflow-hint-dependencies, but if you do stack install --local-bin-path bin it fails with Could not find module 'Data.Finite' when you try to interpret something.
I'm having trouble using the npm sqlite3 package with electron. I'm compiling my electron app from Typescript files to Javascript, bundling them with browserify, and then running the main bundle to launch the main process.
But when I try to use sqlite3, I have problems. I've tried using electron-rebuild as its own separate step before compiling the typescript. I've tried installing sqlite3 with a --build-from-source flag. But whenever I try to run my main bundle, I get a "package.json does not exist" error, which seems to be coming from node-pre-gyp code in my main bundle, which is from the sqlite3 module.
Does anyone have any ideas as to what I'm doing wrong? I don't understand why the code is building itself again with node-pre-gyp when I already rebuilt it with electron-rebuild. I have a package.json in the root directory of the project, but the main bundle is in (root)/build/js-bundles, and the code is looking for package.json in (root)/build.
I know my description isn't all that clear, so if anything isn't obvious I'll do my best to clarify. (The program works fine when I remove the dependency on sqlite3).
Okay, so the problem is that I was using browserify to bundle the sqlite3 dependency. By excluding sqlite3 with the --exclude flag, the problem disappeared.
The issue seems to be that building sqlite3 generates a sqlite3.js file whose sole purpose is to find (and load?) the built node-sqlite3.node binary -- but only at runtime. When sqlite3 is bundled and the bundle is run, it will attempt to locate the binary, but it can't, because my bundle isn't in the node_modules/sqlite directory, it's in my build directory. By excluding sqlite3 from the browserify bundling, at run-time, the import * as sql from "sqlite3" will find node_modules/sqlite3/sqlite3.js, find the binary, and then load it into the program.
The lesson seems to be that while browserify knows how to bundle standard NodeJs modules like fs and path, bundling custom native node modules from npm doesn't work. The program has to find it at run-time.
I don't know anything about the inner workings of NodeJs and how the program knows to look for sqlite3 in build/../node_modules/sqlite3 (I didn't know that it could), so I'd be happy if anyone more knowledgeable could provide details.
Also, even after excluding sqlite3, I still had problems because I hadn't built sqlite3 against my version of electron. Resources for doing this can be found at electron-rebuild in the general case, or in the case of sqlite3, at mapbox/node-sqlite3 in the Installing section.
I am trying to compile and run TSP problem in charm++ framework. The Code is mentioned in the State_Space_SearchEngine directory inside TSP_SE folder. I have compiled it as per the README file mentioned in the directory. As it says to run 'make OPTS=-O3' command in //tmp/libs/ck-libs/state_space_searchengine/ that I have done. And after doing this when I run the TSP_SE application using 'make OPTS=-O3' command I am getting these errors.
Please help me out.Compilation Error
To fix the error all you need to do is make the mainchare class (Main) inherit from CBase_Main in file main.C of the TSP_SE directory.
This fix has been incorporated into the mainline development version of Charm++ and will be a part of the Charm++ v6.8.0 release. Thanks for pointing it out.
New Grunt user here who is using a lot of new tools (npm nodejs) today.
I've got Grunt "installed" and have been able to create a grunt.js file using the init task as described here: http://net.tutsplus.com/tutorials/javascript-ajax/meeting-grunt-the-build-tool-for-javascript/ and here: https://github.com/cowboy/grunt/blob/master/docs/getting_started.md. But whenever I run the "grunt" command I get an error:
Windows Script Host
Script: c:\users\[]\Documents\code\grunt\grunt.js
Line: 2
Char: 1
Error: 'module' is undefined
Code: 800A1391
Source: Microsoft JScript runtime error
As explained in the FAQ, you need to type grunt.cmd instead on Windows because the OS tries to launch grunt.js
Or you can install grunt-cli globally instead. This package will run any version of Grunt if it's been installed locally to your project.
SOLVED !!
So, this problem occur because windows by default associative < *.js > files
with >>
"Microsoft Windows Based Script Host".
grunt need to open by default with (grunt.cmd).
it easy to slove, by change default app (open with..)
Guide :
Go to any javascript file with "js" extension. (any file)
Right-Click(mouse) > Properties > "Opens with:" Change...(button)
Choose Notepad ( or any javascript IDE ).
PROBLEM SOLVED ! :)
good luck
If you're getting a "Microsoft JScript runtime error" that means that node.js isn't even getting invoked; instead Windows Script Host is trying to run your code. That's probably a problem with filetype associations; IIRC Windows defaults to trying to execute a ".js" file with WSH. You may wind up having to create a shortcut to your script, specifying a command line (probably something like "node %1") and a starting directory in order to make sure that it's executed properly.
It would help if you could tell us exactly how you're trying to invoke your code.
it seems that in the latest versions of the grunt modules, you would have to do the following to have it work under windows:
remove any globally installed grunt
npm uninstall -g grunt
install grunt-cli globally
npm install -g grunt-cli
install grunt locally into your project
npm install grunt
installing grunt (v0.4.x) globally does not seem to create the necessary grunt.cmd anymore. it seems that the recommendation is now to have grunt installed locally to be able to use version-specific Gruntfiles
As Florian F suggested, running grunt.cmd works. This is because of the process Windows is looking for your grunt command.
When typing grunt -h Windows will proceed to look for the following files:
./grunt.cmd
./grunt.* (grunt.js is found in this case which is why you see "module is undefined")
%APPDATA%/npm/grunt.cmd
An alternative to using "grunt.cmd" is to use grunter which simply renames the command to grunter... then you no longer have this problem.
To answer this, first we need to understand that the error is caused because it is being executed by Windows Script Host.
Now, run the code from your cmd promt with the following syntax:
>node <application_name>.js
this will allow the Node.js application to open through V8 JavaScript engine(Google's).
P.S: Please reply back if this has helped in resolving your issue else post the problem you are facing after trying this.
I had a similar issue, the problem is file association, I would recommend:
right click on a .js file and choose open with.
then you choose nodejs/node.exe (somewhere in "program files" folder
then make tick box where it says "always open .js files " (paraphrasing)
That should do the trick.
I went through the same issue when running an old Node project.
The issue was with the name of the js file, it was node.js. So the while running the command node node.js, it was opening up a windows dialogue box.
I just changed the name of the file to app.js and the error flew away.
So, in my case i had tryed all the mentioned above with no result.
But i have fund that im dont type: node in the full sentence as the following snipet
node script.js.And remember never understimate your own miscoding.
Solution:
Go to any javascript file with "js" extension. (any file)
Right-Click(mouse) > Properties > "Opens with:" Change...(button)
Choose Notepad ( or any Javascript IDE like VS Code ).