electron / electron/forge

[Windows] Strings with path parts replaced with undefined

Open
#2,857 5 comments 0 reactions 0 assignees View on GitHub
platform/all plugin/webpack
Dominant language
TypeScript
Stars
7.1k
Forks
641
Avg merge
3d 1h
Merged PRs (30d)
30

Description

### Pre-flight checklist

- [X] I have read the [contribution documentation](https://github.com/electron-userland/electron-forge/blob/master/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [code of conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project uses.
- [X] I have searched the issue tracker for a bug that matches the one I want to file, without success.

### Electron Forge version

6.0.0-beta.63

### Electron version

19.0.1

### Operating system

Windows 11 21H2

### Last known working Electron Forge version

Unknown

### Expected behavior

Strings with paths in them would not be replaced with undefined. That way, files could be read from the disk and used in the app.

### Actual behavior

If a string does contain a path part that points to a file, the entire path aside from the filename is replaced with `undefined`. This is normally accomplished through things like `__dirname`, but the following example shows the behavior with an explicitly-defined string:

```
var path = 'C:\\Users\\example-user\\web\\example-project\\src\\some-path\\some-file.txt';
console.log(path);
// => "undefinedsome-file.txt"
```

I narrowed it down to the `webpack-asset-relocator-loader` plugin. Commenting out this plugin resolves the issue. However, I'm not sure the ramifications of this. Running the app locally and making a build seems to work...but maybe I'll run into issues later.

### Steps to reproduce

1. Create a new project using the Webpack template:

```
npx create-electron-app my-new-app --template=webpack
```

2. Create an empty file at `./src/example/index.html`

3. Add this snippet to `main.js`:

```
const PROJECT_ROOT = process.cwd();
const ASSETS_PATH = path.join(PROJECT_ROOT, 'src', 'example');
const appFilePath = path.join(ASSETS_PATH, 'index.html');
console.log('appFilePath', appFilePath);
```

4. Observe that the logged path is `appFilePath undefinedindex.html`.

> Note: the path must point to a file that actually exists for the bug to present itself.

### Additional information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.