sindresorhus / wallpaper

Manage the desktop wallpaper
MIT License
1.05k stars 92 forks source link

spawn (hardcoded)/macos-wallpaper ENOENT #81

Open bumTomica opened 2 years ago

bumTomica commented 2 years ago

Hello, using

When building dist with electron builder and running the app - the path to macos-wallpaper is for some reason hardcoded to the path of the local project of the device on which it was building.

The problem is the same with asar false and I tried to manually include wallpaper lib in dist and reference it in the project - it works locally but not after the build again.

I didn't even notice this before trying to run the app on another device where there is no locally saved dev directory with macos-wallpaper lib in the same place.

import { screens } from "wallpaper";
// ...
const currentMonitors = await screens();

Sentry error after running the build

Error
spawn /Users/bumtomica/Development/splashy-desktop/dist/wallpaper/source/macos-wallpaper ENOENT
// or
spawn /Users/bumtomica/Development/splashy-desktop/node_modules/wallpaper/source/macos-wallpaper ENOENT

Not sure if I'm doing something wrong with init or build, please advise.

bumTomica commented 2 years ago

Going back to the 5.0.1 version it works. I need to include macos-wallpaper manually to dist folder - and dist is part of the build files. But when I do the same with 6+ version it uses the full hardcoded path.

xrr2016 commented 2 years ago

Same issue, not working at mac. version 6.1.1

FlyingThaCat commented 2 months ago

maybe you could try this i use electron-vite btw its packed on app.asar so you need to exclude it

      const wallpaperModulePath = path.resolve(__dirname, 'node_modules', 'wallpaper')
        .replace('app.asar', 'app.asar.unpacked')
        .replace('out\\main\\', '')
        .replace('out/main/', '');
      const wallpaperModuleUrl = `file://${wallpaperModulePath.replace(/\\/g, '/')}/index.js`;
      const { setWallpaper } = await import(wallpaperModuleUrl);

maybe anyone had better solution