Open
Description
Describe the bug
Cannot use require()
to display image on my machine. During preparation of this bug report I've created the same base code in Codesandbox and it works there.
Did you try recovering your dependencies?
npm --version
6.14.8
Which terms did you search for in User Guide?
require
Environment
Environment Info:
current version of create-react-app: 4.0.0
running from C:\Users\Michael\AppData\Roaming\npm-cache\_npx\13776\node_modules\create-react-app
System:
OS: Windows 10 10.0.17763
CPU: (4) x64 Intel(R) Core(TM) i5-4690K CPU @ 3.50GHz
Binaries:
Node: 12.19.0 - C:\Program Files\nodejs\node.EXE
Yarn: Not Found
npm: 6.14.8 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 86.0.4240.198
Edge: Spartan (44.17763.831.0)
Internet Explorer: 11.0.17763.771
npmPackages:
react: ^17.0.1 => 17.0.1
react-dom: ^17.0.1 => 17.0.1
react-scripts: 4.0.0 => 4.0.0
npmGlobalPackages:
create-react-app: Not Found
Steps to reproduce
- Create app with
npx create-react-app
. - Try to get image element with
<img src={require("path/to/image/image.png")} />
in App.js render return.
Expected behavior
Should display icon two times. Once using import variable, once using required. Works like that on Codesandbox website. Refer to demo below.
Actual behavior
This is how it looks while I'm running minimal example locally in project created with npx create-react-app .
Reproducible demo
https://codesandbox.io/s/react-require-bug-1gh2i?file=/src/App.js:67-292