Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to change node.__dirname to false? #2938

Closed
OualidYousfi opened this issue May 23, 2018 · 5 comments
Closed

Is it possible to change node.__dirname to false? #2938

OualidYousfi opened this issue May 23, 2018 · 5 comments

Comments

@OualidYousfi
Copy link

  • Version:
    20.8.1
  • Target: Windows

In node_modules/electron-webpack/out/main.js, I want to change the node.__dirname variable to false. Is it possible to do so through a webpack.config.js or any other way? Or is there no such freedom?

@develar
Copy link
Member

develar commented May 23, 2018

For what?

@OualidYousfi
Copy link
Author

When I execute "yarn dev" and try to go into development mode it works on Windows. However it doesn't work on Mac or Linux, and it gives me a "not allowed to load local resource" error.

When I change node.__dirname from "!this.isProduction" to "false" development mode works on Mac/Linux as well. No longer get the error. I don't know what the problem is. The file exists and I'm passing along the correct file path.

window.loadURL(url.format({
      pathname: path.join(__dirname, '../../src/index.html'),
      protocol: 'file',
      slashes: true
    }))

That's why I was wondering if you could change node.__dirname, asides from making a change in the package itself.

Thanks for the reply!

@develar
Copy link
Member

develar commented May 23, 2018

Strange. Is it possible to provide demo project?

@OualidYousfi
Copy link
Author

OualidYousfi commented May 23, 2018

Just tested it with electron-webpack-quick-start, on both Windows and Linux. What I did was add an index.html in the src folder. The content doesn't particularly matter. Then edit this in main/index.js.

  if (isDevelopment) {
    //window.loadURL(`http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`)
    window.loadURL(formatUrl({
      pathname: path.join(__dirname, '../index.html'),
      protocol: 'file',
      slashes: true
    }))
  }
  else {
    window.loadURL(formatUrl({
      pathname: path.join(__dirname, 'index.html'),
      protocol: 'file',
      slashes: true
    }))
  }

On Linux (and presumably Mac too) it gave me an "not allowed to load local resource" error.
On Windows the index.html loaded as expected. No error.

Also want to add that when packaging the app for Mac it works fine. There's no error in the build version. The error only occurs when you want to enter development mode.

@develar
Copy link
Member

develar commented May 23, 2018

No need to use own index.html. Use renderer/index.js to put your content using JS.

@develar develar closed this as completed May 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants