I created a test app on the Apple pc with Mac OS Monterey v12.0.1 in order to test the file and folder created.
However, when the file creation script runs with the "node-main": "./index.js" reference in the manifest file, it can not create files and gives the following permission error.
Error: Uncaught Error: EROFS: read-only file system, open './newfile.txt'
Steps followed:
Created the following files:
index.html
index.js
package.json
in the following location: nwjs-sdk-v0.49.1-osx-x64/nwjs.app/Contents/Resources/app.nw
index.js file contents are as follows:
var fs = require('fs');
const file_name = './new-file.txt';
fs.writeFile(file_name, 'Learn NWJS', function (err) {
if (err) throw err;
console.log('File is created successfully.');
});
package.json file contents are as follows:
{
"name": "test-app",
"node-main": "./index.js",
"main": "./index.html"
}
Can anyone please help me to overcome this problem, please?
Env info:
NOTE: I have given permission to the NWJS app itself and also to the app.nw folder 777 in order to see the result but the result is zero.
Thank you.
I'm not sure the issue you are having (presume environment related). But another approach you can take that I've never had issues with is to npm install NW.js.
{
"main": "index.html",
"node-main": "index.js",
"name": "example",
"scripts": {
"start": "nw ."
},
"devDependencies": {
"nw": "0.49.1-sdk"
}
}
If you already have Node installed, I would recommend uninstalling it and using nvm (Node Version Manager) to allow you to easily switch between Node versions. NW.js comes with Node built in, so it usually works best to have the same version of Node globally installed. So being able to easily switch versions is useful.
NW.js 0.49.1 shipped with Node 14.13.1, so that's the version you want to globally install.
package.json to the one above, put it in an empty folder with just the index.html and index.js files next to it on your desktop.nvmnvm install 14.13.1node -vnpm -v (should come with Node)npm install && npm start from the folder with your package.jsonThat will download NW.js to a node_modules folder for you and run it. Any time you want to run it again you just need npm start.