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

[Windows] Strings with path parts replaced with undefined #2857

Open
3 tasks done
jamesplease opened this issue Jun 1, 2022 · 5 comments
Open
3 tasks done

[Windows] Strings with path parts replaced with undefined #2857

jamesplease opened this issue Jun 1, 2022 · 5 comments

Comments

@jamesplease
Copy link

Pre-flight checklist

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project uses.
  • 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
  1. Create an empty file at ./src/example/index.html

  2. 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);
  1. 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

@quolpr
Copy link

quolpr commented Jun 28, 2022

I have the same issue. I can't use sqlite3 in preload.ts due to this bug. The interesting thing — on first run (with yarn start) it works ok but only breaks on fast refresh. Upgrading webpack-asset-relocator-loader to 1.7.2 didn't fix an issue

@quolpr
Copy link

quolpr commented Jun 28, 2022

I also tried #575 (comment) (I added sqlite3 to external dep) and vercel/webpack-asset-relocator-loader#161 seems to be related, but it didn't help

@quolpr
Copy link

quolpr commented Jun 28, 2022

Here is the error on HMR happens (I am on macOS btw):

image

@jamesplease
Copy link
Author

I think that’s a different problem. Maybe try some of the ideas over in #2412

@quolpr
Copy link

quolpr commented Jun 29, 2022

@jamesplease oh you are right! Thanks

@erickzhao erickzhao removed the 19-x-y label Sep 22, 2022
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

4 participants