Project: sahat/hackathon-starter: Error: ENOENT, no such file or directory - node.js

my problem is, that I can't debug (node-inspector) my project anymore, because some files for express couldn't be found. The problem comes only up, when I use the debugger.
Because of this problem, I installed the project approximately 10 times from the scratch. :(
Does anybody of you has an idea, what the reason is?
My system: Windows 7,
Project: "sahat/hackathon-starter"
Express: "version": "4.8.3",
node-inspector 0.7.4
fs.js
fs.statSync = function(path) {
nullCheck(path);
return binding.stat(pathModule._makeLong(path));
};
debugger says: "Error: ENOENT, no such file or directory"
path: "c:\bpr\node_modules\express\lib\node_modules\utils-merge
real path:
path: "c:\bpr\node_modules\express\node_modules\utils-merge
I would think the required path must be wrong, but can't believe it.
Express:index.js
module.exports = require('./lib/express');
Thanks for your help!

Here you'll find the answer.
https://github.com/node-inspector/node-inspector/issues/412
Turn the icon "pause on all exceptions" on the buttom of your console off.

Related

Debugging jest test in VS Code shows "Error: Cannot find module "jest-environment-node"

I have troubles with debugging my jest tests. Maybe I introduce my setup first:
root-dir
test
sample.spec.ts
jest.config.js
package.json
tsconfig.json
The contents of sample.spec.ts:
describe('Sample', () => {
it.concurrent('App', async () => {
expect(true).toEqual(true); // here the breakpoint is set
});
});
So nothing fancy to be debugged here. I installed the Jest Runner extension in VS Code.
However, when I "click" the "Debug" button, right above the it, the debugger starts, but shows an exception:
Exception has occurred: Error: Cannot find module 'jest-environment-<path-to-my-root-dir>\node_modules\jest-environment-node\build\index.js/package.json' from '<path-to-my-root-dir>'e
What is the problem there? In the node_modules directory, the jest-environment-node is there. The path form the exception is not correct, hence it can't find the package.json. But this one I can't influence!
I appreciate your help!
Kind regards to all of you!
I've found the solution to this problem... which isn't a problem at all. It is also answered here: Cannot find module jest-sequencer-#jest/test-sequencer!
So... never ever tick Caught Exceptions and Uncaught Exceptions in VS Code:
Without those two ticks, jest works out of the box.

Electron package - how to write/read files

I have file test.txt in my root directory of app. When I run my app with command npm start, I can write to my file without any problem, but when I make package using electron packager, writing text to my file is not possible anymore - I got error
Error: EACCES: permission denied, open './test.txt'
For this, I'm using node.js filesystem:
fs.writeFile("./test.txt",text,function(err){
if(err) {
return alert(err);
}
alert("saved");
});
How is possible to make this working? And is possible to include some extra folder in my app after package process? Thanks for your help!
There are a lot of options to choose to package your electron app in 2019, so in case you come to this question like I did and are using electron-builder, please try my suggestion below.
If you are using electron-builder to package your application and need to read/write a file that is stored within your solution, you can add it to your files property in your package.json. The properties in this file property are files that are copied when packaging your electron app - reference.
In my example, I was reading/writing to file.json.
let fs = require("fs");
fs.writeFile("./file.json", "data to file", "utf-8", (error, data) => {
if (error){
console.error("error: " + error);
}
});
My folder structure looked like this.
parent-folder
app/
assets/
configs/
images/
resources/
...
file.json
My app was not working after I packed it until I added the following file.json in my "build" property in my package.json.
"build": {
"productName": "MyApp",
"appId": "org.dev.MyApp",
"files": [
"app/dist/",
"app/app.html",
"app/main.prod.js",
"app/main.prod.js.map",
"package.json",
"file.json", // << added this line
],
//...
}
Didn't really found out what the problem was, so I tried another solution, which works for me (my main aim was to save data to some local memory of app).
I used npm package electron-store which is really easy to use.
You can get it by typing this to terminal
npm install electron-store
More info about it here: Electron store
Hope it helps someone else too :-)

ENOENT on writeFileSync works on repl fails on gulp-asset-manifest

I'm using the code on this site to write a gulp file for a Windows aspnet + angularjs app.
I'm running only styles for now, and when I run gulp I get:
Error: ENOENT, no such file or directory 'C:\project\build\manifest-debug.json'
at Error (native)
at Object.fs.openSync (fs.js:502:18)
at Object.fs.writeFileSync (fs.js:1103:15)
at writeManifestFile (C:\project\node_modules\gulp-asset-manifest\index.js:30:8)
at resetManifestFile (C:\project\node_modules\gulp-asset-manifest\index.js:51:5)
at module.exports (C:\project\node_modules\gulp-asset-manifest\index.js:76:5)
at getManifest (C:\project\Gulpfile.js:97:12)
at Gulp.<anonymous> (C:\project\Gulpfile.js:126:15)
at module.exports (C:\project\node_modules\gulp\node_modules\orchestrator\lib\runTask.js:34:7)
at Gulp.Orchestrator._runTask (C:\project\node_modules\gulp\node_modules\orchestrator\index.js:273:3)
Looking at C:\project\node_modules\gulp-asset-manifest\index.js:30:8 I see:
fs.writeFileSync(filename, JSON.stringify(data));
So I ran this on node's REPL:
fs.writeFileSync('C:\\project\\build\\manifest-debug.json', 'hi');
And the file was created correctly.
I tried running gulp again with an existing file and got the exact same error.
I added a console.log(filename); before line 30 on index.js and I got:
./build/manifest-debug.json
So I ran fs.writeFileSync('./build/manifest-debug.json', 'hi'); on REPL from the same folder and it worked too.
Not sure what's going on.
I'm running everything with UAC disabled and on a command prompt with admin rights.
The problem was fs.writeFileSync requires the path to exist.
At the point gulp-asset-manifest was called ./build was nonexistent, because the clean task deleted the entire path.

nodejitsu 400 Error: ENOENT, open '/opt/run/snapshot/package/images/tmp/72118-89rld0.png

I'm using nodejitsu to deploy a simple image upload program with express. In my code I've changed the default upload directory by following command
app.use(express.bodyParser({
uploadDir: __dirname + "/images/tmp"
}));
It's working fine on my localhost but when I'm using nodejitsu I'm getting this error
400 Error: ENOENT, open '/opt/run/snapshot/package/images/tmp/72118-89rld0.png.
Can anybody tell me how to make it work on nodejitsu as well? Actually I'm new to node as well as nodejitsu.
I had the same problem. Try to check directory at application start:
var fs = require('fs'),
upload = __dirname + "/images/tmp";
fs.exists(upload, function (exist) {
if (!exist) {
fs.mkdir(upload);
}
});
It was helpful for me, may be it would helpful for you.
make sure that directory /opt/run/snapshot/package/images/tmp/ exists. Otherways just mkdir those directory
At first check that the directory exist or not. If not then create it and follow the command
sudo jitsu deploy
I think the problem will be solved.

node.js express-coffee Error: ENOENT, no such file or directory

I installed the latest express-coffee and installed node-config too. I created a simple src/config/default.yaml
Database:
db_host: localhost
db_name: test
In my src/models/index.coffee
config = require('config').Database
console.log "host: #{config.db_host}"
But when trying to start the server with cake dev or even cake build && node app I am getting the following error:
Cannot write runtime.json file Error: ENOENT, no such file or directory
Tried searching for the issue here and on Google but wasn't able to find anything. Even the few hits on just ENOENT or node-config runtime.json haven't been helpful. Anyone else run into this problem before ?
It turns out the problem was where config/default.yaml was located. I had to move this to the root directory of the application. Moving it to the root - config/default.yaml fixed the issue.
The error message wasn't very helpful in figuring out what was going on.

Resources