Structure
Cloud
-solution
-app
-common
-index.js
When packaged, the app is in the asar file and i'm not sure how to reference the index.js file in the common folder where the server lives.
In development mode I exec a npm script that goes into the common folder and starts the server.
exec('cd ../ && cd common && npm run server', (err,stdout,stderr) => {
.....
if(err){
log.info(error.stack);
log.info('Error code: ' + error.code);}
}
I get this error in the exec callback when I try to run the script in production
Error: Command failed: npm run server-production
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:\Users\Ibrah\AppData\Local\Programs\Cloud\package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\Ibrah\AppData\Local\Programs\Cloud\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
How can I reference the packaged app server file ?
I'm using both electron-forge and electron-builder to package and build the installer. What I did in my builder config was I included the extraResources key that makes available the specified folder(s) in the dist/{os}-unpacked/resources folder alongside the asar file.
electron-builder
"extraResources": [
{
"from": "../#cloud/common",
"to": "common"
}
],
Now when I exec the node script that is responsible for starting the server it points to the newly moved folder and which contains the script I'm executing. What's important is that I had to set the current working directory to
const runExpress = exec(' npm run server',{cwd:`../cloud/resources/common/`}, (error: any, stdout: any, stderr: any) => {
if (error) {
log.info(error.stack);
log.info('Error code: ' + error.code);
log.info('Signal received: ' + error.signal);
return;
}
else {
log.info('Child Process STDOUT: ' + stdout);
log.info('Child Process STDERR: ' + stderr);
}
});
My final remarks
Since I'm adding a folder to the accessible application directory User/AppData/Programs/YOUR_APPLICATION_NAME/ the source code becomes available to the user. Is that bad? or could I reference the script from inside the app.asar file (I was searching inside the app.asar for my server folder logic and found the package.json exist but without the scripts strangely enough). Would be great if someone can follow up to this.
Related
My Electron application compiles and packages under MacOS without any problems but when it comes to Windows, I can't seem to make it work.
Here's the debug output:
Error: node-gyp failed to rebuild '[appfolder]\release\app\node_modules\cpu-features'.
For more information, rerun with the DEBUG environment variable set to "electron-rebuild".
Error: `C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 1
at NodeGyp.rebuildModule ([appfolder]\node_modules\electron-rebuild\lib\src\module-type\node-gyp.js:117:19)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async ModuleRebuilder.rebuildNodeGypModule ([appfolder]\node_modules\electron-rebuild\lib\src\module-rebuilder.js:94:9)
at async ModuleRebuilder.rebuild ([appfolder]\node_modules\electron-rebuild\lib\src\module-rebuilder.js:124:14)
at async Rebuilder.rebuildModuleAt ([appfolder]\node_modules\electron-rebuild\lib\src\rebuild.js:145:13)
at async Promise.all (index 7)
at async Rebuilder.rebuild ([appfolder]\node_modules\electron-rebuild\lib\src\rebuild.js:104:13)
at async [appfolder]\node_modules\electron-rebuild\lib\src\cli.js:154:9
Error: Command failed: ..\..\node_modules\.bin\electron-rebuild --parallel --force --types prod,dev,optional --module-dir .
at checkExecSyncError (child_process.js:790:11)
at execSync (child_process.js:863:15)
at Object.<anonymous> ([appfolder]\.erb\scripts\electron-rebuild.js:17:11)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Module.m._compile ([appfolder]\node_modules\ts-node\src\index.ts:1455:23)
at Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Object.require.extensions.<computed> [as .js] ([appfolder]\node_modules\ts-node\src\index.ts:1458:12)
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) {
status: 4294967295,
signal: null,
output: [ null, null, null ],
pid: 2700,
stdout: null,
stderr: null
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! elapp#4.5.0 electron-rebuild: `node -r ts-node/register ../../.erb/scripts/electron-rebuild.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the elapp#4.5.0 electron-rebuild 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\elodie\AppData\Roaming\npm-cache\_logs\2022-04-17T20_38_46_086Z-debug.log
error Command failed with exit code 1.
failedTask=installAppDeps stackTrace=Error: C:\Program Files\nodejs\node.exe exited with code ERR_ELECTRON_BUILDER_CANNOT_EXECUTE
Output:
yarn install v1.22.18
[1/4] Resolving packages...
success Already up-to-date.
$ npm run electron-rebuild && npm run link-modules
Tried this with Node v14, 16 and 17 to no avail.
EDIT: Missed the actual error while posting. Here's the error from C++ compilation step:
> elapp#4.5.0 electron-rebuild [appfolder]\release\app
> node -r ts-node/register ../../.erb/scripts/electron-rebuild.js
Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
conpty.cc
conpty.cc
[appfolder]\release\app\node_modules\node-pty\src\win\conpty.cc : fatal error C1083: Cannot open compiler generated file: '[folder]\obj\conpty\src\win\conpty.obj': Permission denied [[appfolder]\release\app\node_modules\node-pty\build\conpty.vcxproj]
path_util.cc
conpty_console_list.cc
win_delay_load_hook.cc
win_delay_load_hook.cc
Creating library [folder]\conpty_console_list.lib and object [folder]\conpty_console_list.exp
Creating library [folder]\conpty.lib and object [folder]\conpty.exp
conpty_console_list.vcxproj -> [folder]\\conpty_console_list.node
conpty.vcxproj -> [folder]\\conpty.node
Agent.cc
conpty_console_list.vcxproj -> [folder]\\conpty_console_list.node
Agent.cc
[appfolder]\release\app\node_modules\node-pty\deps\winpty\src\agent\Agent.cc : fatal error C1083: Cannot open compiler generated file: '[appfolder]\release\app\node_modules\node-pty\build\deps\winpty\src\Release\obj\winpty-agent\deps\winpty\src\agent\Agent.obj': Permission denied [[appfolder]\release\app\node_modules\node-pty\build\deps\winpty\src\winpty-agent.vcxproj]
EDIT 2: Running the same command as an administrator lead to another error:
yarn install v1.22.18
[1/4] Resolving packages...
success Already up-to-date.
$ npm run electron-rebuild && npm run link-modules
> elapp#4.5.0 electron-rebuild C:\Users\elodie\Projects\elapp\release\app
> node -r ts-node/register ../../.erb/scripts/electron-rebuild.js
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Error output:
- Searching dependency tree
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.
gyp: Call to 'cmd /c "cd shared && UpdateGenVersion.bat 2c681018ca7311741a0022e3a170bf60174590b2"' returned exit status 0 while in deps\winpty\src\winpty.gyp. while loading dependencies of binding.gyp while trying to load binding.gyp
× Rebuild Failed
An unhandled error occurred inside electron-rebuild
node-gyp failed to rebuild 'C:\Users\elodie\Projects\elapp\release\app\node_modules\node-pty'.
For more information, rerun with the DEBUG environment variable set to "electron-rebuild".
Error: `gyp` failed with exit code: 1
I'm using npm install -g yo gulp to install yeoman and this is the error I'm getting
npm WARN deprecated cross-spawn-async#2.2.5: cross-spawn no longer requires a build toolchain, use it instead
C:\Usr\local\gulp -> C:\Usr\local\node_modules\gulp\bin\gulp.js
C:\Usr\local\yo -> C:\Usr\local\node_modules\yo\lib\cli.js
C:\Usr\local\yo-complete -> C:\Usr\local\node_modules\yo\lib\completion\index.js
> yo#3.1.0 postinstall C:\Usr\local\node_modules\yo
> yodoctor
Yeoman Doctor
Running sanity checks on your system
√ No .bowerrc file in home directory
√ Global configuration file is valid
√ NODE_PATH matches the npm root
√ No .yo-rc.json file in home directory
√ Node.js version
{ Error: Couldn't find the 'yo' binary. Make sure it's installed and in your $PATH
at notFoundError (C:\Usr\local\node_modules\yo\node_modules\cross-spawn-async\lib\enoent.js:8:11)
at verifyENOENT (C:\Usr\local\node_modules\yo\node_modules\cross-spawn-async\lib\enoent.js:43:16)
at ChildProcess.cp.emit (C:\Usr\local\node_modules\yo\node_modules\cross-spawn-async\lib\enoent.js:30:19)
at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
errno: 'ENOENT',
code: 'ENOENT',
syscall: 'spawn yo',
cmd: 'C:\\WINDOWS\\system32\\cmd.exe /s /c "yo "--version""' }
× yo version
{ Error: Couldn't find the 'yo' binary. Make sure it's installed and in your $PATH
at notFoundError (C:\Usr\local\node_modules\yo\node_modules\cross-spawn-async\lib\enoent.js:8:11)
at verifyENOENT (C:\Usr\local\node_modules\yo\node_modules\cross-spawn-async\lib\enoent.js:43:16)
at ChildProcess.cp.emit (C:\Usr\local\node_modules\yo\node_modules\cross-spawn-async\lib\enoent.js:30:19)
at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
errno: 'ENOENT',
code: 'ENOENT',
syscall: 'spawn yo',
cmd: 'C:\\WINDOWS\\system32\\cmd.exe /s /c "yo "--version""' }
√ npm version
Found potential issues on your machine :(
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents#1.2.9 (node_modules\gulp\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents#1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
+ gulp#4.0.2
+ yo#3.1.0
updated 2 packages in 23.31s
Run the following command to see where npm puts global packages
npm config get prefix
You'll get output similar to this
/usr/local/Cellar/node/10.5.0_1
Copy the output or path and then using any code editor open your .bashrc or .zshrc file depending on the terminal you use and paste like so
export PATH="$PATH:"/usr/local/Cellar/node/10.5.0_1/bin/""
Then after saving run
source ~/.zshrc
Like Xander Cage said.
I have uninstalled node.js -> procedure here
I have restarted my PC.
Then I installed again node.js
It work.
The above didn't work for me at all.
The following solved my problem:
clean installed nodejs and followed steps by dv-here in thread: https://github.com/zkat/npx/issues/100
Note that my npm kept pointing to C:\usr...
I think I set the npm config set prefix= to something mistakenly due to which I was >getting the error. Here's how I fixed it:
Open CMD in "Administrator" mode.
npm cache clear --force
npm install
npm config set cache C:\Users\myname\AppData\Roaming\npm-cache
npm config set prefix C:\Users\myname\AppData\Roaming\npm
I just ran into this issue on MacOS, and saw that all of my global npm binaries were symlinked into the /usr/local/bin directory, except for yo. I created a symlink using this command:
ln -s /usr/local/Cellar/node/12.10.0/bin/yo /usr/local/bin/yo
(Yours may vary)
And yo is now callable.
I had same issue and I really didn't want uninstall nodejs as I have a lot of package installed.
Tried also with the second answer and did not worked.
Then I found this ticked, that is been closed:
https://github.com/yeoman/yeoman/issues/1716
install with yarn command for me worked.
yarn global add yo
Seem then the installation went through with also binary installed.
Nevermind try to install it with npm getting same error, so looking for provide more infos
I don't know why I'm getting this error. Meteor-up is a brilliant. Whenever I run the deploy command it gets to a time and terminates. Could it be that a timeout has been set for the server to finish uploading the files?
C:\Programs\contract\schoolapps\.deploy>mup.cmd deploy --cached-build
┌─────────────────────────────────────┐
│ │
│ update available 1.3.2 => 1.3.3 │
│ To update, run npm i -g mup │
│ │
└─────────────────────────────────────┘
Not building app. Using build from previous deploy at
C:\Users\Kehinde\AppData\Local\Temp\mup-meteor-58e876b4-e682-4ecf-9d41-168fa46a5b19
Started TaskList: Pushing Meteor App
[xxx.xxx.xx.xx] - Pushing Meteor App Bundle to The Server
[=============== ] 41% 630.4sevents.js:160
throw er; // Unhandled 'error' event
^
Error: write ECONNRESET
at exports._errnoException (util.js:1020:11)
at WriteWrap.afterWrite (net.js:800:14)
C:\Programs\contract\schoolapps\.deploy>
After the upload was successful I got this error:
[xxx.xxx.xx.xx] x Prepare Bundle: FAILED
-----------------------------------STDERR-----------------------------------
Error response from daemon: No such container: myappsupload
The command '/bin/sh -c cd /built_app/programs/server && npm install --unsafe-perm' returned a non-zero code: 1
Error response from daemon: No such container: myappsupload
Error: failed to start containers: myappsupload
-----------------------------------STDOUT-----------------------------------
mnpm ERR! meteor-dev-bundle#0.0.0 install: `node npm-rebuild.js`
npm ERR! Exit status 254
npm ERR!
npm ERR! Failed at the meteor-dev-bundle#0.0.0 install script 'node npm-rebuild.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the meteor-dev-bundle package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node npm-rebuild.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs meteor-dev-bundle
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls meteor-dev-bundle
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /built_app/programs/server/npm-debug.log
----------------------------------------------------------------------------
C:\Programs\contract\myappsupload\.deploy>
This is the mup.js file:
module.exports = {
servers: {
one: {
// TODO: set host address, username, and authentication method
host: 'xxx.xxx.xx.xx',
username: 'root',
// pem: './path/to/pem'
password: 'xxxxxxxxxxxxxxxx'
// or neither for authenticate from ssh-agent
}
},
app: {
// TODO: change app name and path
name: 'schoolapps',
path: '../',
servers: {
one: {},
},
buildOptions: {
serverOnly: true,
},
env: {
// TODO: Change to your app's url
// If you are using ssl, it needs to start with https://
ROOT_URL: 'http://schoolapps.com',
MONGO_URL: 'mongodb://localhost/meteor',
},
// ssl: { // (optional)
// // Enables let's encrypt (optional)
// autogenerate: {
// email: 'email.address#domain.com',
// // comma separated list of domains
// domains: 'website.com,www.website.com'
// }
// },
docker: {
// change to 'kadirahq/meteord' if your app is using Meteor 1.3 or older
image: 'abernix/meteord:base',
args: [
//'--link=myCustomMongoDB:myCustomMongoDB', // linking example
'--memory-reservation 300M' // memory reservation example
],
},
// Show progress bar while uploading bundle to server
// You might need to disable it on CI servers
enableUploadProgressBar: true,
deployCheckWaitTime: 150
},
mongo: {
version: '3.4.1',
servers: {
one: {}
}
}
};
There is no substitute for reading the documentation before you ask questions.
You should also update the mup package like it's suggesting.
There is a setting deployCheckWaitTime which might be applicable, but it looks like it's failing in the upload. I'm not sure if it includes the upload time, but it would be worth increasing it to check.
Ten minutes is a long time to be only 41% through the upload, so your upload connection is slow - can you tether through your phone for better speed?
If that doesn't work, have a look to see if the disk is full on the target server, or if some other timeout is getting in the way (like your computer going to sleep)
I do not know if it is still relevant, but maybe my answer will help someone else dealing with the same problem.
The task "Prepare bundle" was introduced in the version 1.3.0 of Meteor Up (see release notes):
After the bundle is uploaded to each server, a new task is run called "Prepare bundle". It installs the Meteor npm dependencies, rebuilds native modules, and stores the result in a docker image. This has a few benefits:
The time in meteor.deployCheckWaitTime no longer needs to include the time to install npm dependencies
When installing dependencies fails, it does not continuously restart until meteor.deployCheckWaitTime expires, and running with --verbose shows the full logs from npm install
Dependencies are only installed once during each deploy. This means that mup start, mup restart, and mup reconfig are all much faster.
From the version 1.3.1 this task can be disabled by adding the option app.docker.prepareBundle in mup.js and setting it to false. I dealt with the same error a few weeks ago and with this workaround I was able to deploy my application to DigitalOcean.
I'm following the guidelines for setting up the NPM feed
and connecting to it.
https://www.visualstudio.com/en-us/docs/package/npm/npmrc
I've also got the 'Auth-Token' generated as part of the 'Connect to Feed' dialog and updated my user '.npmrc' file with the token following the instructions provided.
My 'NodeJs' is latest version as well.
My OS is : Win7 64x
I want to publish standard NPM packages to TFS to be used for Build as our build system is isolated from internet.
Here is the error I get when I publish a package.
C:\Users\user\Source\Repos\project\Node\node_modules\which>npm publ
ish
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\
node_modules\\npm\\bin\\npm-cli.js" "publish"
npm ERR! node v7.10.0
npm ERR! npm v4.2.0
npm ERR! code ENEEDAUTH
npm ERR! need auth auth required for publishing
npm ERR! need auth You need to authorize this machine using `npm adduser`
npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\userAppData\Roaming\npm-cache\_logs\2017-
05-19T20_40_46_348Z-debug.log
My config settings:
C:\Users\user\Source\Repos\project\Node\node_modules\which>npm conf
ig list
; cli configs
scope = ""
user-agent = "npm/4.2.0 node/v7.10.0 win32 x64"
; userconfig C:\Users\user\.npmrc
always-auth = true
registry = "http://server:8080/tfs/DefaultCollection/_packaging/Project-NuGet/np
m/registry"
; builtin config undefined
prefix = "C:\\Users\\user\\AppData\\Roaming\\npm"
; node bin location = C:\Program Files\nodejs\node.exe
; cwd = C:\Users\user\Source\Repos\project\Node\node_modules\which
; HOME = C:\Users\user
; "npm config ls -l" to show all defaults.
Thanks,
Mamrez
After restarting the developer laptop and tried the steps in the
https://www.visualstudio.com/en-us/docs/package/npm/npmrc
again; It worked!! and I can publish the NPM packages
I am trying to install "Twitter-Node" (npm install twitter-node). Version .3.2-pre of Node JS.
When I try and install I receive the follow error. Any thoughts on what I may be doing wrong? Seems like a pretty straight forward install to me. I was able successfully install socket-io too...
m ERR! Error: twitter-node#0.0.2 preinstall: `./build.sh`
npm ERR! `sh` failed with 1
npm ERR! at ChildProcess.<anonymous> (/usr/local/lib/node/.npm/npm/0.2.12- 1/package/lib/utils/exec.js:25:18)
npm ERR! at ChildProcess.emit (events.js:34:17)
npm ERR! at ChildProcess.onexit (child_process.js:164:12)
npm ERR!
npm ERR! Failed at the twitter-node#0.0.2 preinstall script.
npm ERR! This is most likely a problem with the twitter-node package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! ./build.sh
Simple solution
Just grab it from here:
https://github.com/patmcnally/twitter-node
The module on npm is old (last update August 31th) and broken by design, it compiles its own base64 encoder instead of using Node's built in functionality.
To install:
Download the archive and extract it
cd into the folder and run npm install .
Have a nice day :)
Old answer
The install runs gcc to compile a base64 module that depends on nodes Buffer class (the C++ implementation), since there were quite some changes to that in 3.x, it explodes!
Waf: Entering directory `/home/ivo/.local/lib/node/.npm/twitter-node/0.0.2/package/vendor/node-base64/build'
[1/2] cxx: base64.cc -> build/default/base64_1.o
../base64.cc: In function ‘v8::Handle<v8::Value> base64_encode_binding(const v8::Arguments&)’:
../base64.cc:178: error: ‘class node::Buffer’ has no member named ‘data’
../base64.cc:178: error: ‘class node::Buffer’ has no member named ‘length’
../base64.cc: In function ‘v8::Handle<v8::Value> base64_decode_binding(const v8::Arguments&)’:
../base64.cc:199: error: ‘class node::Buffer’ has no member named ‘data’
../base64.cc:199: error: ‘class node::Buffer’ has no member named ‘length’
Waf: Leaving directory `/home/ivo/.local/lib/node/.npm/twitter-node/0.0.2/package/vendor/node-base64/build'
Build failed: -> task failed (err #1):
{task: cxx base64.cc -> base64_1.o}
This commit removed the two members and replaced them with static inlined methods.
In .npm/twitter-node/0.0.2/package/vendor/node-base64/base64.cc you need to replace the lines 177/178 and 198/199 which look like this:
Buffer *buffer = ObjectWrap::Unwrap<Buffer>(args[0]->ToObject());
char *str = base64_encode((unsigned char*)buffer->data(), buffer->length(),&len);
With this:
Local<Object> buffer = args[0]->ToObject();
char *str = base64_encode((unsigned char*)Buffer::Data(buffer), Buffer::Length(buffer),&len);
Then run npm rebuild twitter-node and you're done! Don't use install, as it will re-download and overwrite the changes.
PS: I had to use require('twitter-node#0.0.2') to get it to import, since npm didn't create the symlink in .local/lib/node but you can easily fix that on your own.
Update
I did take a look at the module, this is hilarious, they compile a 80kb lib which is prone to failure with changed to Node.js just to use a base64 encode ONE TIME.
// Returns a Basic Auth header fit for HTTP.
var basicAuth = function basicAuth(user, pass) {
return "Basic " + b64.encode(user + ":" + pass);
};
This does the exact same thing and doesn't explode on every other change to Node.js:
new Buffer(user + ':' + pass).toString('base64')