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

Error: Cannot find module 'logo.png' #1271

Closed
moshest opened this issue May 17, 2017 · 9 comments
Closed

Error: Cannot find module 'logo.png' #1271

moshest opened this issue May 17, 2017 · 9 comments

Comments

@moshest
Copy link

moshest commented May 17, 2017

I have a component Logo with Logo.css and logo.png files.

When I use the image on the css file like:

.root {
  background: url('logo.png') no-repeat 0 0;
}

I got the following error: Error: Cannot find module 'logo.png'

If I change the path to url('/logo.png') and put the logo image on the public folder, everything works fine but that's breaks the component-based UI development principle.

@langpavel
Copy link
Collaborator

Try ./logo.png

@moshest
Copy link
Author

moshest commented May 17, 2017

Same results. Please see guidelines on css-loader library.

I tries to import the image file from the Logo.js component class and it's works:

import image from './logo.png';

assert.equal(image, '/assets/../logo.png?xxxx');

I can't figure out why it's failed on the CSS file.

@frenzzy
Copy link
Member

frenzzy commented May 17, 2017

https://github.com/webpack-contrib/css-loader#url

/* src/components/Header/Header.css */
.root {
  background-image: url('./banner.png'); /* src/components/Header/banner.png */
}

@moshest
Copy link
Author

moshest commented May 17, 2017

url('./logo.png'), url('logo.png'), url(./logo.png)and url(logo.png) give me the same error.

@ucay
Copy link

ucay commented May 23, 2017

is this related with webpack's issue?
webpack-contrib/css-loader#74

@moshest
Copy link
Author

moshest commented May 23, 2017

Yes. Looks like it's the same issue.

Disabling the modules: true on css-loader options break all the images on the website but the warning gone.

@moshest
Copy link
Author

moshest commented May 23, 2017

I open a new project of "react-start-kit" and change the file Header.css to:

.bannerTitle {
  background: url('logo-small.png');
  /*...*/
}

And the build was failed with error: Cannot find module 'logo-small.png'.

When I change it to:

.bannerTitle {
  background: url('./logo-small.png');
  /*...*/
}

Everything works fine.

That's incompatible with the guidelines of css-loader library and can case problems when requiring third-party style files.

@frenzzy
Copy link
Member

frenzzy commented May 23, 2017

For third-party libraries you may to disable CSS Modules, then url('logo-small.png') also will work fine.

@moshest
Copy link
Author

moshest commented May 28, 2017

Confirm. Working.

Thanks!

@moshest moshest closed this as completed May 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants