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

Error on load image on React-native: Unexpected character #6691

Closed
fuechter opened this issue Mar 28, 2016 · 57 comments
Closed

Error on load image on React-native: Unexpected character #6691

fuechter opened this issue Mar 28, 2016 · 57 comments
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@fuechter
Copy link

react-native-cli: 0.1.10
react-native: 0.22.2
SO Mobile: Android
SO: Mac

I'm try display a image on a component on React-native, but I don't know why this error happens...

Example of code:

render () {
    let { convenience } = this.props
    return (
      <View style={{flexDirection: 'row', height: 50}}>
        <Text style={{marginRight: 30}}>{convenience.name}</Text>
        <Image source={require('./icons___favorito_ativo.png')} />
      </View>
    )
}

@seanfuture
Copy link

Get the same error but only when overwriting an image already loaded and cmd-r is pressed. To resolve the issue temporarily it seems the image must be re-exported / overwritten and then a 2nd cmd-r to reload results in clearing the error message. Happens regularly at the moment for myself at least. Haven't had time to research further.

@seanfuture
Copy link

Seems related to image map as noted here in this issue enzymejs/enzyme#253

@seanfuture
Copy link

@sylvainbaronnet
Copy link

Same problem, fixed by re-exporting image as @seanfuture said

@sylvainbaronnet
Copy link

Restarting the packager fix it too

@dsibiski
Copy link
Contributor

@facebook-github-bot answered

@facebook-github-bot
Copy link
Contributor

Closing this issue as @dsibiski says the question asked has been answered. Please help us by asking questions on StackOverflow. StackOverflow is amazing for Q&A: it has a reputation system, voting, the ability to mark a question as answered. Because of the reputation system it is likely the community will see and answer your question there. This also helps us use the GitHub bug tracker for bugs only.

@facebook-github-bot facebook-github-bot added the Ran Commands One of our bots successfully processed a command. label Mar 30, 2016
@seanfuture
Copy link

FYI - StackOverflow link: http://stackoverflow.com/questions/36252381/error-on-load-image-on-react-native-unexpected-character/36289632#36289632 .. Don't believe this issue should have been closed as the above mentioned "fixes" aren't really fixes - Instead they're workarounds. Error still comes up often and a full restart of the packager is needed. Most definitely a prevalent and serious bug in the packager. Taken a brief look, but packager code doesn't immediately reveal the cause although my suspicion is that Node.js is trying to process the file / file change as an asset.

@yashvekaria
Copy link

yashvekaria commented Apr 15, 2016

I too faced the same error. After a lot of trying, I restarted the packager, and the app picked up the image. So the solution is: Restart the packager.

Hope this helps.

@zipzit
Copy link

zipzit commented Apr 23, 2016

I know this is going sound pretty weird, but I'm going to add this comment in case anybody else gets here. I created a index.ios.js file by copying a simple sample from an internet example (actually something at https://rnplay.org) I kept getting "unexpected character" errors. I'm using Atom.io as my script tool. I was thinking perhaps I had an encoding issue with the wrong character set. I've confirmed I'm using UTF-8

So I was using the (left/right) arrow keys on my keyboard, and I notice the cursor would stop moving for two keyboard arrow pushes, right at the location identified in my Emulator Red Screen of Disaster. It was like there were two invisible characters in my code. I played with this for a pretty long time to confirm. I was able to highlight the "hidden" characters and delete them.

After deletion, the new code works great.

Bizarre. Not sure what was there. (Note: I copied the Slider Example Code from https://rnplay.org/apps/5FsfPA and I used a "Select All" and Command-C to do the copying and Command-V to paste... if anybody wants to repeat the experiment)

And yes, I know how silly this sounds. Perhaps others have hit the same roadbump?

@duzliang
Copy link

duzliang commented Aug 26, 2016

stop the server and execute react-native start again will resolve this problem

@ShashankaNataraj
Copy link

@duzliang Stopping and starting the server did get rid of the error message, but Im getting a blank screen now!

@jaredly
Copy link
Contributor

jaredly commented Nov 23, 2016

the packager should not require this though -- this is a bug, and even though there's a workaround, it should be fixed. this isn't a SO type question, it's a "please fix the packager"

@tomchambers2
Copy link

Still having this issue. Happened in various occasions, most reliably when I open an image being used in the react native app with preview (hit space bar in finder) on OSX.

@felipecocco
Copy link

+1

@ColtHands
Copy link

Switching react-native from 40 to 38 helped, i don't think this should have happen

@ColtHands
Copy link

Another suggestion is to watchman watch-del-all and running the RN packager server with the --resetCache option.

@radelcom
Copy link

radelcom commented Feb 2, 2017

started seeing this today after updating to RN v0.40.0. Tried all the workarounds mentioned in this thread but no luck 😞

@fdb
Copy link

fdb commented Feb 21, 2017

I have this issue as well. Turns out it is because I have spaces in the project path:

  • This works: /Users/fdb/Desktop/myproject/icons/settings.png
  • This doesn't: /Users/fdb/Dropbox (Personal)/myproject/icons/settings.png

Running watchman watch-del-all has no effect — only moving to a path without spaces does.

@mrlords1
Copy link

I had this same error,
When i try stop n start server see this log:

myfile.png: Unexpected character '�' (1:0)

1 | �PNG
| ^
2 | �
3 |
4 | IHDR���X���d�IT pHYs.#.#�x�?v�tEXtSoftwareAdobe Fireworks CS6輲��tEXtCreation Time11/14/166z�� IDATx��}w�dU��{��\��'�0PMRXP�"
+�JPW@�u
soo I try user randon .PNG google image, and it work.

After I need re export my file.

@joeferraro
Copy link

@fdb I do not have spaces in my project path and still experience this issue.

@radelcom
Copy link

@fdb that seems to be the case for me as well.

@cyclops24
Copy link

@woshi82 I also have + in project parent name and after remove it everything goes OK.
Is it a bug or + is not acceptable for project folder name (maybe an undocumented limitation). I didn't find info or limitation about React-Native project name or path in docs.

@mitchjam
Copy link

I had a * in my folder path and after I removed it my error was gone.

@agersoncgps
Copy link

I have no special chaecters in my path and it happens to me any time I make a change to the image and re-save it.

@silkyland
Copy link

This work for me
just type "react-native link" in terminal
The reason is because you create new assets folder in your project and react-native may not know it

sorry for my bad English

@idrisdopico
Copy link

idrisdopico commented May 4, 2017

Not using dropbox, don't have a + in the code. When restarting the terminal and simulator it works fine, but like others have said, this is a workaround. Not a fix.

Working on IOS.

@dcu-sharepoint
Copy link

dcu-sharepoint commented May 8, 2017

as suggested by many here; restarted the entire process environment and now everything works. However, this is a BUG that NEEDS FIXING without any workarounds if this is going to make it to the real world. Going to SO with a question like this brings out the arrogant admins where they take GREAT pleasure telling you how to ask intelligent questions and what is an intelligent question is. To them, this IS NOT and intelligent question so no answer is given. I speak from frustrating experiences with SO, so I've learned to read, not speak.

The problem with this type of bug is that when you're deep in the dev cycle and you get this bug, some of us forget about the bug and end up wasting an enormous amount of time troubleshooting. when it happens more that once, it makes you feel like an idiot for NOT remembering what the solution/workaround is! BAD!

@spenghang
Copy link

spenghang commented May 17, 2017

Check that if your project path has a special symbol, like '+'.

@jhalborg
Copy link

Restart of packager works, but is a bit annoying :-)

@deathemperor
Copy link

Just got this on 0.44.2. my path has '-' not sure if it's the reason. Restarting the packager fixed.

@ridhoassuryadi
Copy link

I have a same problem, because my image's name has '-','+','_'. the solution is try react-native link or restart packager.

@zakster12
Copy link

zakster12 commented Jun 15, 2017

I have very easy fix for the problem that works perfectly for me. I remove the problematic image from the assets folder and add it again. And the red screen is gone. Just drag & drop. Restart is not needed.

@SudoPlz
Copy link
Contributor

SudoPlz commented Jun 17, 2017

Removing spaces and parenthesis from my path fixed that issue for me too.

@Phenek
Copy link

Phenek commented Jun 27, 2017

Hello there, I also get this issue!
"react-native run-android" work fine on Windows.
But I got " Unexpected character '?'" error on Mac OS when compile on IOS or Android Simulator.

I'm using Typescript with :
"devDependencies": {
"types/immutable": "^3.8.7",
"types/react": "^15.0.23",
"types/react-native": "^0.43.9",
"babel-jest": "19.0.0",
"babel-preset-react-native": "1.9.1",
"jest": "19.0.2",
"react-test-renderer": "16.0.0-alpha.6",
"shadow-flux": "^1.0.13"
}

Let me know if you find something, cause this issue turn me crazy..
regards,

@mr-bat
Copy link

mr-bat commented Jul 10, 2017

I solved(!?) this problem by creating a copy of the image and replacing the original one, then renamed the image. This indeed is a weird bug, your photo at once becomes useless.

@ShubhamOjha
Copy link

Closing the server and restarting it works just fine.

@Rebaiahmed
Copy link

@sylvainbaronnet thanks it's working for me 👍

@jan-happy
Copy link

@ShubhamOjha: I don't think this is really a solution. One nice thing about react native is the hot reloading feature. Which is made completely useless if you use images in your project that change during development.

@milon87
Copy link

milon87 commented Aug 9, 2017

faced the same problem and solved by renaming the .png to .jpg and it works.
I don't know what's wrong with the .png file extension.

@paranoidjk
Copy link

same problem here, any process?

@gblaender
Copy link

Same problem, but nothing worked. Killed and restarted the packager, replaced the image... Same unexpected character red screen. Really frustrating.. Newbie dev here :)

@cpojer
Copy link
Contributor

cpojer commented Sep 1, 2017

This is fixed for the next release of react-native, where we have many HMR improvements. cc @grabbou can tell you when that goes out but in your current version of react-native it isn't magically going to be fixed from one minute to the next.

@cpojer cpojer closed this as completed Sep 1, 2017
@danilags
Copy link

danilags commented Sep 11, 2017

Try terminate your terminal server and react-native run-android / ios 🗡

@mingsong2
Copy link

As @danilags says

  • Try terminate your packager server
  • rm -fr $TMPDIR/react-* clear the react-native cache
  • rerun your xcode
    hope this helps you

@jgreen01su
Copy link

tl;dr Always use .png not .PNG

I had this same issue. Using an uppercase PNG file extension will also case this error.

@norby3
Copy link

norby3 commented Mar 27, 2018

foobar.JPG causes this really annoying error
foobar.jpg works

.. lotta people wasted a lot of time .. not a confidence booster

@facebook facebook locked as resolved and limited conversation to collaborators Sep 1, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Sep 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests