0

I am building my app on windows.

I am trying to do some path manipulation using the path module.

I have done this:

import { app, BrowserWindow } from 'electron'
import path;
console.log('path.sep:', path.sep);

It is giving me / but that is wrong. It should should be \ as I am on windows. This is the same reason I got this bug here - path.dirname on Windows path is giving `.` - but no one mentioned that to me.

Does anyone know how to make path module properly work on Windows in electron?

Is the only solution this:

import pathOrig from 'path'
import url from 'url'
import os from  'os'

const PLATFORM = os.platform();
const path = PLATFORM.startsWith('win') ? pathOrig.win32 : pathOrig;
Blagoh
  • 1,225
  • 1
  • 14
  • 29
  • 1
    I think It is `\\` in win32 see https://github.com/nodejs/node/blob/master/lib/path.js#L1144 – aristotll Jul 29 '17 at 17:03
  • Yes but its not giving me that :( I have no idea why but it seems my path module is not detecting that its windows :( – Blagoh Jul 29 '17 at 17:06
  • 1
    From the code `if (process.platform === 'win32') module.exports = win32; else module.exports = posix;` So check `process.platform` – aristotll Jul 29 '17 at 17:08
  • Thanks @aristotll - I tried it and it is not showing `platform` is even in process, here is screenshot of `console.log('process:', process)` - http://i.imgur.com/mLkTfTC.png – Blagoh Jul 29 '17 at 17:11
  • @aristotll I am using webpack can this be my problem? – Blagoh Jul 29 '17 at 17:12
  • @aristotll I added to my webpack config `node: { __dirname: false, __filename: false, process: false }`. now `process.platform` is giving `win32` however `path.sep` is still `/` instead of `\` :( – Blagoh Jul 29 '17 at 17:16
  • 1
    Can you print the path object by `console.log(path);` and see if it is really `win32` rather than `posix`. – aristotll Jul 29 '17 at 17:22
  • 1
    Thank yo uvery much for your help, this is the console log - http://i.imgur.com/uiayOLK.png - it seems its correct now :) i had to add to my webpack config, `target: 'electron'` – Blagoh Jul 30 '17 at 00:01

0 Answers0