Can't import static files like images
See original GitHub issueversion: v2.1.1
additional webpack config to next.config.js:
config.module.rules.push(
{test: /\.(png|jpeg)$/, loader: 'url-loader?limit=8192'}
)
then in my component:
import image from '../static/enen.png'
it comes the error:
This module was not found:
* /static/enen.png in ./pages?entry
To install it, you can run: npm install --save /static/enen.png
{ Error: Cannot find module '/static/enen.png'
...
I have tried to change the url as ‘/static/enen.png’ , and in the css-in-jsx:
p {
background-image: url('../static/enen.png')
}
//or
p {
background-image: $(require('../static/enen.png'))
}
all above comes the same error: can’t find the module, I can get it using <img src="../static/enen.png"/>
hope your help.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:40
- Comments:51 (6 by maintainers)
Top Results From Across the Web
I can't reference an image in Next.js - Stack Overflow
Next.js can serve static files, like images, under a folder called public in the root directory. Files inside public can then be referenced ......
Read more >Basic Features: Static File Serving - Next.js
js can serve static files, like images, under a folder called public in the root directory. Files inside public can then be referenced...
Read more >How to manage static files (e.g. images, JavaScript, CSS)
Set the STATIC_ROOT setting to the directory from which you'd like to serve these files, for example: STATIC_ROOT = "/var/www/example.com/static/" · Run the ......
Read more >Images, fonts, and assets - Storybook - JS.ORG
Images, fonts, and assets · Import assets into stories · Serving static files via Storybook Configuration · [⚠️ Deprecated] Serving static files via...
Read more >Serving Static Files - Storybook
You can import any media assets by simply importing (or requiring) them as shown below. import React from 'react'; import { storiesOf }...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If you add the image to the
/static/
and then add the<img src="/static/image.png"/>
? There is no need to load the image via the import.@paulobarcelos it’s not a strong opinion. With our SSR setup, it’s kind a hard to it. (Since we don’t run webpack in the server) It’s doable, but we’ve much important other stuff to do.
@laoqiren why it’s not working simply use the image path like this: