简体   繁体   中英

When I try to import an HTML file into React, I get an error

I saw one beautiful star animation in codesandbox link I want to apply it in my project, for this I created a separate HTML file and put the code from the link. Now i am trying to render html file in my jsx

import htmlFile from 'Assets/Styles/Test.html';

function Page () {
   return <iframe src={htmlFile}></iframe>
}

But I am getting this kind of error

在此处输入图像描述

What is it connected with? How can I solve this problem?

It looks like you are trying to import an HTML file into your JavaScript code, but the JavaScript module system doesn't know how to handle HTML files.

One solution is to use an HTML loader to handle the import of the HTML file. In your webpack configuration, you can add a rule that tells webpack to use the HTML loader for HTML files.

Here's an example of how you might do this:

module: {
  rules: [
    {
      test: /\.html$/,
      use: 'html-loader'
    }
  ]
}

Hopefully that helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM