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.

"react-native link" silently fails to link non-font assets

See original GitHub issue

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

Environment: OS: macOS Sierra 10.12.6 Node: 7.10.0 Yarn: 0.27.5 npm: 4.2.0 Watchman: 4.7.0 Xcode: Xcode 9.0.1 Build version 9A1004 Android Studio: 2.3 AI-162.4069837

Packages: (wanted => installed) react: 16.0.0-alpha.12 => 16.0.0-alpha.12 react-native: 0.48.4 => 0.48.4

Steps to Reproduce

  1. Put font and non-font assets into a project directory (e.g. ./assets/fonts/file.ttf ./assets/text/file.txt).
  2. Add the following section to package.json:
"rnpm": {
    "assets": [
      "assets/text",
      "assets/fonts"
    ]
  },
  1. Run react-native link.

Expected Behavior

All asset files are copied to iOS and Android projects. If that’s not possible, an error or warning is reported in console. If for some reason that’s not possible either, this behavior is documented.

Actual Behavior

file.ttf is copied as expected. file.txt is not copied, console reports that linking was successful, there are no errors or warnings.

Reproducible Demo

https://github.com/andriichernenko/rnpm-non-font-assets-repro

Here’s the code in /node_modules/react-native/local-cli/link/ios/copyAssets.js that copies the assets:

/**
 * Copies each file from an array of assets provided to targetPath directory
 *
 * For now, the only types of files that are handled are:
 * - Fonts (otf, ttf) - copied to targetPath/fonts under original name
 */
module.exports = function copyAssetsAndroid(files, targetPath) {
	const assets = groupFilesByType(files);

	(assets.font || []).forEach(asset =>
		fs.copySync(asset, path.join(targetPath, 'fonts', path.basename(asset)))
	);
};

As the comment says, “the only types of files that are handled are fonts”. One would think that other types are handled somewhere else, but that’s not the case.

Seems like this has been reported before (see https://github.com/facebook/react-native/issues/14468). There’s also a related PR: https://github.com/facebook/react-native/pull/12047, but it wasn’t merged.

Are there any plans to implement handling of resources of all types?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
unimonkiezcommented, Jan 25, 2018

I wrote react-native-asset which solves just that.
It also unlinks old files automatically, which I find pretty helpful.

Currently supports only fonts and sound files, but just finished writing it so might add more in the future. Added support for any file extension.

1reaction
grabboucommented, Oct 30, 2017

Is there a chance it will be added?

I think yeah, shouldn’t be an issue. Just submit PR adding it if you think it’s a reasonable default. I think it would be cool to be able to import txt file into a string, but that’s against Node behavior AFAIK.

Now I need to figure out how to get its content

I don’t have time to dig into it, but look how Image module handles it - it works the same way. I belive given that id of an asset, you should be able to parse it.

Let me know if you need any further assistance, happy to help. As I said, I don’t have enough time to dig into it myself.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't link assets (fonts) in react native >= 0.60 - Stack Overflow
Well, finally, I linked my fonts,. I just renamed my file react-native-config.js to react-native.config.js and it worked.
Read more >
error Unrecognized command "link"., install google fonts - Reddit
r/reactnative - error Unrecognized command "link"., install google fonts. i can't install any google font, how i can fix that?
Read more >
Changelog | Meteor API Docs
Throwing error when trying to send email in a production environment but without a mail URL set. PR, Issue. facebook-oauth@1.11.0. Updated Facebook API...
Read more >
atp 6-02.53 techniques for tactical radio operations
Tactical Digital Information Link Joint Terminals . ... Internal brigade combat net radio assets provide communications and information ...
Read more >
https://www.fairfaxhonda.com/static/assets/libs/ht...
lib/attributes-to-props.js","../lib/dom-to-react.js","../node_modules/html-dom-parser/lib/client/constants.js","../node_modules/domelementtype/lib/index.js" ...
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