You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thus is throwing me this error:
Is there a flag in tsconfig.json or an alternative way to load the images in the source tag? (the image is in where it says to be)
Sorry, I'll defer to your answer if it works. It was (and sort of is) kind of a pain from our end to get a full React Native setup together to test. If others still run into the problem, we'll take a look.
I also have a problem with react-native, typescript and including images. As far as I see it, the problem is that typescript does not copy resources into the build folder. But I have no solution yet.
Reacted by ManAnRuck, Adam, Pete Petrash, Provash Shoumma, Denis Evgrafov, Danny Lee, Andrii Malykhin and Andrii Chernenko
Adam (@adamconservis) I'm still having an issue copying over static resources to /artifacts even while using react-native-typescript-transformer — was there any additional config you may have done to enable this? I don't see static resources mentioned in the docs. Thanks!
Update: I somehow overlooked the section on absolute paths. I ended up relocating my static assets to <rootDir>/static/, adding "baseUrl": "." to tsconfig.json, and adding a new package.json file in there whose contents are simply {"name":"static"} — I can now import/require static assets in my TS modules like so:
Pete Petrash (@petekp) when I do this, it works fine but tsc complains at me that it cant find module assets. I named my package.json { "name": "assets"}. Any idea on a workaround for that?
Iksela (@AleskiWeb) Have you tried changing the baseUrl in tsconfig.json? Mine is "baseUrl": ".". If that doesn't work, then I'm not sure, but it is likely related to your tsconfig configuration.
Activity
DanielRosenwasser commentedon Jul 7, 2016
I believe this is related to React Native, not a TypeScript one. StackOverflow is probably a better venue for questions like this.
For what it's worth, according to this answer on SO, you can prefix your path with
image!to load it this way.sintylapse commentedon May 19, 2017
nschurmann, Daniel Rosenwasser (@DanielRosenwasser), this is definitely the problem of typescript. You just need to install
npm install @types/nodeThis question is: Why do you, Daniel Rosenwasser (@DanielRosenwasser), close an issue, without providing a reasonable answer???
DanielRosenwasser commentedon May 19, 2017
Sorry, I'll defer to your answer if it works. It was (and sort of is) kind of a pain from our end to get a full React Native setup together to test. If others still run into the problem, we'll take a look.
oferRounds commentedon Sep 14, 2017
Hi nschurmann and Nick Malezh (@sintylapse)
Facing the same issue. I installed
@types/nodebut the situation did not change - still unable to resolve. Any idea?oferRounds commentedon Sep 18, 2017
Daniel Rosenwasser (@DanielRosenwasser) - maybe you’d have an idea?
Klabauterman commentedon Dec 4, 2017
I also have a problem with react-native, typescript and including images. As far as I see it, the problem is that typescript does not copy resources into the build folder. But I have no solution yet.
eassymo commentedon Dec 16, 2017
any update?
adamconservis commentedon Dec 18, 2017
Here is a node module that helps RN work with Typescript, this solved the issue for me. https://github.com/ds300/react-native-typescript-transformer
This solution was suggested by the team at artsy
petekp commentedon Jan 24, 2018
Adam (@adamconservis) I'm still having an issue copying over static resources to
/artifactseven while usingreact-native-typescript-transformer— was there any additional config you may have done to enable this? I don't see static resources mentioned in the docs. Thanks!Update: I somehow overlooked the section on absolute paths. I ended up relocating my static assets to
<rootDir>/static/, adding"baseUrl": "."totsconfig.json, and adding a newpackage.jsonfile in there whose contents are simply{"name":"static"}— I can now import/require static assets in my TS modules like so:oferRounds commentedon Mar 10, 2018
For me the solution was to move the
imagesfolder out of thesrcfolder, placing it at the same level.eassymo commentedon Mar 22, 2018
I'm ussing "copyfiles" package to copy assets folder into transpiled code:
package.json
Error of "module not found" gone, but image is not shown.
EDIT: i was ussing import * as image from 'path'; ussing require('path') prints image as desired.
AleskiWeb commentedon Mar 28, 2018
Pete Petrash (@petekp) when I do this, it works fine but tsc complains at me that it cant find module
assets. I named my package.json{ "name": "assets"}. Any idea on a workaround for that?petekp commentedon Mar 28, 2018
Iksela (@AleskiWeb) Have you tried changing the
baseUrlintsconfig.json? Mine is"baseUrl": ".". If that doesn't work, then I'm not sure, but it is likely related to yourtsconfigconfiguration.MichelDiz commentedon Apr 5, 2018
I have the same issue, I'll try (right now) this https://github.com/expo/expo-asset-utils
UPDATE: No way with expo-asset-utils.
UPDATE 2:
"add-assets": "copyfiles -u 1 src/assets/**/* out-dir/"from eassymo is working for me! xDjustinwaite commentedon Apr 8, 2018
I created an answer on SO for this issue outlining two options: https://stackoverflow.com/a/49715468/4216035