react / react/metro

Can't require image with spaces, etc. in filename

Open
#1,609 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
5.6k
Forks
696
Avg merge
8m
Merged PRs (30d)
7

Description

Hi folks, I'm getting the same error seen in this very old RN issue:

https://github.com/facebook/react-native/issues/10364

Here is the stacktrace that shows this is ocurring in Assets.js

Error: ENOENT: no such file or directory, scandir '/Users/andrew/Work/Code/projects/Failure/Mobile/ReactNative/failure/.%2Fassets%2Fimages'
    at Object.readdir (node:internal/fs/promises:956:18)
    at getAbsoluteAssetRecord (/Users/andrew/Work/Code/projects/Failure/Mobile/ReactNative/failure/node_modules/@expo/metro/node_modules/metro/src/Assets.js:114:17)
    at getAsset (/Users/andrew/Work/Code/projects/Failure/Mobile/ReactNative/failure/node_modules/@expo/metro/node_modules/metro/src/Assets.js:224:18)
    at Server._processSingleAssetRequest (/Users/andrew/Work/Code/projects/Failure/Mobile/ReactNative/failure/node_modules/@expo/metro/node_modules/metro/src/Server.js:436:20)
    at Server._processRequest (/Users/andrew/Work/Code/projects/Failure/Mobile/ReactNative/failure/node_modules/@expo/metro/node_modules/metro/src/Server.js:535:7)

I've confirmed that the file name had a space in it; when I renamed it to not have a space, it works just fine. Strangely, this did not happen in 0.79 of React Native; I recently upgraded to 0.81 of RN, and this happened. Though it says it's expo related, when forking this repo, the node_module file for Assets.js was the same as here, so I assume it's the correct repo.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in metro/src/Assets.js at getAbsoluteAssetRecord and getAsset, using the reported stack trace as the entry point. Reproduce the asset request with a filename containing spaces under React Native 0.81 and compare behavior with 0.79. Done means the asset loads without the ENOENT path containing encoded filename characters.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react-native
Domain
build-system, mobile-dev, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.