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

Static file importing in npm package is not working #6048

Closed
3 tasks done
awmleer opened this issue Aug 18, 2021 · 5 comments · Fixed by #6115
Closed
3 tasks done

Static file importing in npm package is not working #6048

awmleer opened this issue Aug 18, 2021 · 5 comments · Fixed by #6115
Assignees
Labels
🐛 Bug 🎒 Bundler Refers to CodeSandbox's In-Browser Bundler

Comments

@awmleer
Copy link

awmleer commented Aug 18, 2021

🐛 bug report

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project
    adheres to.
  • I have searched the issue tracker for an issue that matches the one I want
    to file, without success.

Description of the problem

https://codesandbox.io/s/antd-mobile-static-file-test-1vv0d?file=/src/App.tsx

In this sandbox I used the ErrorBlock component from package antd-mobile. In the ErrorBlock component, there is a svg file import:

import DefaultErrorIcon from '../../assets/default.svg';

But when I render this component in codesandbox, this svg image gets 404.

image

image

How has this issue affected you? What are you trying to accomplish?

I'm the maintainer of antd-mobile package. I'd like to make some demos about antd-mobile v5 alpha using codesandbox. But currently the svg images are broken.

To Reproduce

Just use the sandbox link below.

Link to sandbox: link (optional)

https://codesandbox.io/s/antd-mobile-static-file-test-1vv0d?file=/src/App.tsx

Your Environment

Software Name/Version
Сodesandbox
Browser Chrome 92.0.4515.131
Operating System macOS 11.5.2
@sannek
Copy link
Contributor

sannek commented Aug 26, 2021

Hi, thanks for reporting - that sure looks like a bug. I'll pass it on to someone who can (hopefully) fix this!

@awmleer
Copy link
Author

awmleer commented Aug 26, 2021

Thanks a lot!

@DeMoorJasper DeMoorJasper self-assigned this Aug 27, 2021
@lbogdan lbogdan added the 🎒 Bundler Refers to CodeSandbox's In-Browser Bundler label Sep 7, 2021
@DeMoorJasper
Copy link
Member

DeMoorJasper commented Sep 8, 2021

We run svg's through svgr when using the react template (so we return a react component not an svg, although currently it seems to be broken), not sure how we should go about resolving this as I assume react-scripts has the same issue?

Nevermind, just found the logic we should follow for this: https://github.com/facebook/create-react-app/blob/bb64e31a81eb12d688c14713dce812143688750a/packages/babel-plugin-named-asset-import/index.test.js will change this tomorrow and disable svgr for now...

@awmleer
Copy link
Author

awmleer commented Sep 9, 2021

Seems like the behavior of create-react-app is:

import { ReactComponent as Logo } from './logo.svg'; will import the svg image as Logo component.
import logo from './logo.svg'; will import it as file link.

@awmleer
Copy link
Author

awmleer commented Sep 10, 2021

It works now! Thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug 🎒 Bundler Refers to CodeSandbox's In-Browser Bundler
Projects
None yet
4 participants