0

I have a problem when loading CSS in react.

My source code is like this.

const Index = ({ .... }) => {
...
   useEffect(() => {
   ...
      console.log('data : ', data);
      // require('#a/b/c/d/e.css');
      require(data.src);

When I load the css using string url, It works properly. But when I load the css as variable, it can not work.

Error log is like this.

Cannot find module '#a/b/c/d/e.css'
webpackEmptyContext
webpack:~ sync:2

and Console.log is like this.

data :  
{key: "9999", src: "#a/b/c/d/e.css"}
key: "9999"
src: "#a/b/c/d/e.css"

I want to use url as variable. Is there any solution about this?

Thanks.

1 Answer 1

1

Webpack has no way of knowing what the value of the variable is, so it cannot compile the file.

You should define the path clearly or webpack will throw errors.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. Based on your comment, I found a QnA about web pack. github.com/webpack/webpack/issues/6680 Have a good day :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.