DaveK
DaveK

Reputation: 590

Electron Project cannot file with correct path

I have the following function that is trying to load a .ejs file with the following path.

function PaintNewOpponent() {

ejs.renderFile('views/NewOpponent.ejs', {pPlayer:pPlayerLocal}, function(err, str) {
    $("#AddPlayerDialog").html(str);
    alert(err)

    RenderEvents();
    FillInModalinformation()        
});

}

I have run an alert check with __dirname and have discovered that I am in the correct directory. Here is a screenshot of my explorer window from Visual Studio Code.

enter image description here

the directory html is in my root directory. __dirname returns that I am in /html/js. PaintNewOpponent() is inside my NewOpponent.js file. Yet the ejs.renderFile call comes back in error saying it cannot file the file. Everything is in place.

If necessary here is package.json file

{
  "name": "combattracker",
  "version": "3.0.0",
  "description": "AutoHARP 3: Combat Tracker",
  "main": "index.js",
  "license": "ISC",
  "scripts": {
    "start": "electron .",
    "package-mac": "electron-packager . --overwrite --platform=darwin --arch=x64 --icon=assets/icons/mac/icon.icns --prune=true --out=release-builds",
    "package-win": "electron-packager . electron-tutorial-app --overwrite --asar=true --platform=win32 --arch=ia32 --icon=assets/icons/win/icon.ico --prune=true --out=release-builds --version-string.CompanyName=CE --version-string.FileDescription=CE --version-string.ProductName=\"AutoHARP 3\"",
    "package-linux": "electron-packager . electron-tutorial-app --overwrite --asar=true --platform=linux --arch=x64 --icon=assets/icons/png/icon.png --prune=true --out=release-builds"
  },
  "author": "David Klecker",
  "dependencies": {
    "bootstrap": "^4.5.2",
    "bootstrap-sass": "^3.4.1",
    "commonjs": "0.0.1",
    "ejs": "^3.1.5",
    "electron": "^10.1.2",
    "electron-alert": "^0.1.11",
    "electron-reload": "^1.5.0",
    "embed-js": "^5.0.4",
    "jquery": "^3.5.1",
    "parser": "^0.1.4",
    "popper.js": "^1.16.1",
    "uniter": "^2.16.0",
    "xml2js": "^0.4.23",
    "xmlbuilder": "^15.1.1"
  },
  "devDependencies": {
    "electron-packager": "^15.1.0"
  }
}

Upvotes: 0

Views: 154

Answers (1)

spring
spring

Reputation: 18487

I don't know if this will help but what I do is to build an absolute path using the path library (actually I use upath for cross platform compatibility because I often need to save the path to a file).

const iconPath = upath.joinSafe(__dirname, 'app', 'assets', 'win_icon_64x64.png');

Upvotes: 2

Related Questions