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

TypeError: placeholder.indexOf is not a function #104

Closed
elrumordelaluz opened this issue Oct 26, 2020 · 5 comments
Closed

TypeError: placeholder.indexOf is not a function #104

elrumordelaluz opened this issue Oct 26, 2020 · 5 comments
Labels

Comments

@elrumordelaluz
Copy link
Contributor

Describe the bug
Declaring a placeholder using require gives the error shown in the title.

To Reproduce
Steps to reproduce the behavior:

  1. Go to this sandbox
  2. Look that declaring require('./images/cover.svg') throws an error.
  3. Commenting this line shows that this doesn't happen with the src prop

Expected behavior
This used to word until I updated to create-react-app@4 (which implies to remove node_modules folder and reinstall dependencies, so maybe is related to another change). But seems that the error reproduce well in Codesandbox

Screenshots
Screenshot 2020-10-26 at 12 20 03

Desktop (please complete the following information):

  • OS: macOS
  • Browser Firefox
  • Version 81.0.2 (64-bit)

Additional context
I know that work ok just importing the two files, but in my case I am using several images that render dynamically so i used to pass the values like require('./images/image_' + n + '.svg')

@bluebill1049
Copy link
Member

bluebill1049 commented Oct 28, 2020

I don't think we support reqiure import. (string only)

@elrumordelaluz
Copy link
Contributor Author

elrumordelaluz commented Oct 28, 2020

Thank you @bluebill1049, however for some reason works perfect for me (also in react@17), before update react-scripts.

Outside this importing stuff, the end result of the require should be s string, right?

@elrumordelaluz
Copy link
Contributor Author

Ok, I solved this way

<SimpleImg
  placeholder{require(`./path/to/img`).default}
/>

Don't know where is the root of the problem, probably bundler side. Will continue to investigate however.

@bluebill1049
Copy link
Member

interesting... I suspect it returns a string now.

@elrumordelaluz
Copy link
Contributor Author

yes, also before returns a string but for some reason without needed the .default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants