question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

with-electron-typescript show example of image path mapped correctly

See original GitHub issue

Bug report

Describe the bug

The electron example is showing how Next.js can be used with Electron to create Desktop Apps https://github.com/vercel/next.js/tree/canary/examples/with-electron-typescript

When running the default example it runs fine, but after adding an image behaviour is not consistent. The guide gives and example to load an image: <img src="/my-image.png" alt="my image" /> https://nextjs.org/docs/basic-features/static-file-serving

The image loads fine when using the dev server npm start but not when running npm run dist.

If you add debug toolbar to the electron-src/index.ts mainWindow.webContents.openDevTools()

You can see that urls in css are processed correctly, but not urls in html.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Clone the example at: https://github.com/vercel/next.js/tree/canary/examples/with-electron-typescript
  2. Place an image in the directory at: /renderer/public/my-image.png
  3. Add the image to: /renderer/pages/index.tsx <img src="/my-image.png" alt="my image" />
  4. View it working using: npm start
  5. View the error using npm run dist

Expected behavior

Image paths should be mapped correctly whether running in dev mode or production.

Screenshots

npm start Screen Shot 2020-09-13 at 5 35 50 PM

npm run dist Screen Shot 2020-09-13 at 5 35 16 PM

System information

  • OS: macOS Catalina 10.15.6
  • Browser: Chrome 85.0.4183.102
  • Version of Next.js: 9.5.1
  • Version of Node.js: 14.4.0

How to fix

Move image under a static folder at: /renderer/public/static/my-image.png and update url to be: <img src="/static/my-image.png" alt="my image" />

This doesn’t seem to be documented, but works!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:13
  • Comments:6

github_iconTop GitHub Comments

5reactions
Ciberuspscommented, Jan 12, 2021

Thanks a lot saved much time

4reactions
danbrowncommented, Nov 23, 2021

Bruh, I was using a subfolder inside public/images to serve images and realize was not showing in electron, solution was change all image paths to public/static/images/image-name.png. The folder name HAS to be static, not just be a subfolder of public directory. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Correct path for img on React.js - Stack Overflow
In create-react-app relative paths for images don't seem to work. Instead, you can import an image: import logo from './logo.png' // relative path...
Read more >
Copy UNC network path (not drive letter) for paths on mapped ...
What I'd like to be able to do is to copy the full real path (not the drive letter) from Windows Explorer to...
Read more >
WAMP: Properly configuring image paths on local server
It's more a Wamp problem that an EE one,. But open this file, inside your wamp install: wamp/bin/apache/conf/extra/httpd-vhosts.conf.
Read more >
Map a network drive in Windows - Microsoft Support
In the Folder box, type the path of the folder or computer, ... trying to connect to might be turned off, or you...
Read more >
Mapped Network Drives don't Show in Image for Windows
The UNC path (\\Server\Share) should be used instead of a mapped drive. If using Windows 10, make sure the system is updated current...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found