简体   繁体   English

InvalidCharacterError:无法在“文档”上执行“createElement”:提供的标签名称(“/static/media/index.c6592bb6.ts”)不是有效名称

[英]InvalidCharacterError: Failed to execute 'createElement' on 'Document': The tag name provided ('/static/media/index.c6592bb6.ts') is not a valid name

I have a react app that I am trying to convert to use typescript我有一个反应应用程序,我试图将其转换为使用打字稿

but I'm getting the following error: InvalidCharacterError: Failed to execute 'createElement' on 'Document': The tag name provided ('/static/media/index.c6592bb6.ts') is not a valid name.但我收到以下错误: InvalidCharacterError: Failed to execute 'createElement' on 'Document': The tag name provided ('/static/media/index.c6592bb6.ts') is not a valid name.

What does this error even mean?这个错误甚至意味着什么? It looks like it doesn't like the typescript extension看起来它不喜欢打字稿扩展

Any ideas how to fix?任何想法如何解决?

In my case, I was building my web app and I had created a javaScript file in the IDE IntelliJ.就我而言,我正在构建我的 Web 应用程序,并在 IDE IntelliJ 中创建了一个 javaScript 文件。 But in the folder, the file name was missing the suffix ".js".但是在文件夹中,文件名缺少后缀“.js”。 So when I used 'npm run dev' command in the terminal, it failed to find the file I had created.因此,当我在终端中使用“npm run dev”命令时,它无法找到我创建的文件。

If it is the same for you, then just go to the folder and add the suffix ".js" in the file name.如果对你来说是一样的,那么只需转到文件夹并在文件名中添加后缀“.js”即可。

I think it's a bug in IntelliJ, Hopefully they may fix it later on.我认为这是 IntelliJ 中的一个错误,希望他们以后可以修复它。

The problem for me was that I was trying to render ts files.我的问题是我试图渲染 ts 文件。 React can't 'create elements' from ts files. React 无法从 ts 文件“创建元素”。 TS files need to be transpiled to JS. TS 文件需要转译为 JS。 I thought that my babel loader was configured correctly but it wasn't.我以为我的 babel loader 配置正确,但事实并非如此。 The babel loader wasn't checking for ts or tsx files. babel 加载器没有检查 ts 或 tsx 文件。

I got this error also and I don't see it described in the solutions was a mistake on my part of having quotes as part of my Route component assignment.我也遇到了这个错误,我在解决方案中没有看到它的描述是我将引号作为我的 Route 组件分配的一部分的错误。

<Route component="{ NotFound }" />

Removing the quotes solved the issue.删除引号解决了这个问题。

<Route component={ NotFound } />

Just in case it hasn't been specified before, I had the same issue with Home document and it was because I used this:以防万一之前没有指定,我在 Home 文档中遇到了同样的问题,这是因为我使用了这个:

<Route path="/" component="{Home}" />

Instead of this而不是这个

<Route path="/" component={Home} />

Note the quote marks.注意引号。 Hope this helps someone.希望这可以帮助某人。

It means you have code trying to do this:这意味着您有代码尝试执行此操作:

document.createElement("/static/media/index.c6592bb6.ts")

...directly or indirectly. ...直接或间接。 Since /static/media/index.c6592bb6.ts isn't a valid tag name (like div or span ), it fails.由于/static/media/index.c6592bb6.ts不是有效的标记名称(如divspan ),因此失败。

Not sure if this Helps but I had the same error message and it was flagging the following:不确定这是否有帮助,但我收到了相同的错误消息,并标记了以下内容:

ReactDOM.render ( <App />, document.getElementById('root'));

For me it was a simple mistake (as mentioned by someone already) of not having the file with correct extension.对我来说,没有正确扩展名的文件是一个简单的错误(正如有人已经提到的那样)。 In my case it was SearchBox child that was saved as a text file and not as "SearchBox.js".就我而言,它是 SearchBox 子项,它被保存为文本文件,而不是“SearchBox.js”。 In your case it would be the "Index" file.在您的情况下,它将是“索引”文件。 Granted I am completely new to this and am still learning, just thought I would share as reading previous responses to your question helped me fix my issue!当然,我对此完全陌生并且仍在学习,只是想我会分享,因为阅读以前对您的问题的回答帮助我解决了我的问题!

First of all, check that there is a file in your source folder or in public folder with no proper extension mean's like "首先,检查您的源文件夹或公共文件夹中是否有一个文件没有正确的扩展名,例如“

index指数

" add a proper extension to it or delete it. " 为其添加适当的扩展名或将其删除。

I'm usually a lurker, but I've never seen two people talk past each other so completely before. 我通常是个潜伏者,但我从未见过两个人如此彻底地交谈过。 One group is talking about upgrading a react JS project to typescript, and the other group is focused on the error message and why it would happen in a JS environment. 一组讨论将React JS项目升级为打字稿,另一组讨论错误消息以及在JS环境中发生错误的原因。

This error message happens at this step: 此错误消息发生在此步骤:

"Now rename ClientApp\\src\\App.js to ClientApp\\src\\App.tsx" “现在将ClientApp \\ src \\ App.js重命名为ClientApp \\ src \\ App.tsx”

... in THIS process: ...在此过程中:

https://jonhilton.net/new-aspnet-core-react-project/ https://jonhilton.net/new-aspnet-core-react-project/

I have no solution yet. 我还没有解决办法。 Still looking. 还在寻找。

haha, I have the same error and bothered me for a long time.哈哈,我也有同样的错误,困扰了我很久。

import GuessLikeList from './GuessLikeList/GuessLikeList.jsx';

and error和错误

Failed to execute 'createElement' on 'Document': The tag name provided ('./GuessLikeList/GuessLikeList.jsx') is not a valid name.

It means can not execute with '.jsx',so you have to change filename extension or import some modules to compile jsx这意味着不能用'.jsx'执行,所以你必须改变文件扩展名或导入一些模块来编译jsx

I got this error.我收到了这个错误。 It happened that the name of the js folder had spaces at the end of it.碰巧js文件夹的名字后面有空格。 Seems React doesn't recognise space in folder/file names.似乎 React 无法识别文件夹/文件名中的空格。

In my own case, I had the error in my App.js.在我自己的情况下,我的 App.js 中有错误。 The App.js had a wrong name on the route path like this So I had to correct the path name and that fixed my error. App.js 在这样的路由路径上有一个错误的名称所以我不得不更正路径名称并修复了我的错误。

In my case, it was just importing asset like this就我而言,它只是导入这样的资产

import { ReactComponent as PaintIcon } from "./assets/paint.svg";

instead of代替

import PaintIcon from "./assets/paint.svg";

Thanks.谢谢。

There might be a dummy file in the name of index which not having ".js" as the suffix.索引名称中可能有一个虚拟文件,没有“.js”作为后缀。

Or Your index file might not have ".js" suffix.或者您的索引文件可能没有“.js”后缀。

So rename it所以重命名

in my case i was importing SVG like:就我而言,我正在导入 SVG,例如:

import SidebarButton from '../../assets/images/sidebarbutton.svg';

And just using that:只是使用它:

<SideBarButtonImg>

This fixed the issue:这解决了这个问题:

const SideBarButtonImg = () => (
  <button style={{height: '100%'}}>
    <img
      src={sidebarbutton}
      alt=""
      style={{
        height: '100%',
        background: '#fff',
      }}
    />
  </button>
)

As others have mentioned, one of the reasons this can happen is how you named your file.正如其他人所提到的,发生这种情况的原因之一是您如何命名文件。 I for example had component.Js instead of component.js .例如,我有component.Js而不是component.js

确保在文件名以及导入时添加了 .js

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 InvalidCharacterError:无法在“文档”上执行“createElement”:提供的标记名称(“/static/media/tab1.fab25bc3.png”)不是有效名称 - InvalidCharacterError: Failed to execute 'createElement' on 'Document': The tag name provided ('/static/media/tab1.fab25bc3.png') is not a valid name InvalidCharacterError:无法在“文档”上执行“createElement”:提供的标签名称(“/static/media/avatar.6043f57a.png”)不是有效名称 - InvalidCharacterError: Failed to execute 'createElement' on 'Document':The tag name provided ('/static/media/avatar.6043f57a.png') is not a valid name 无法导入图像:InvalidCharacterError:无法在“文档”上执行“createElement”:提供的标签名称不是有效名称 - Unable to import images: InvalidCharacterError: Failed to execute 'createElement' on 'Document': The tag name provided is not a valid name React Uncaught DOMException:无法在“文档”上执行“createElement”:提供的标签名称(“<div> &#39;) 不是有效名称 - React Uncaught DOMException: Failed to execute 'createElement' on 'Document': The tag name provided ('<div>') is not a valid name 未捕获的 DOMException:无法在“文档”上执行“createElement”:提供的标签名称 - Uncaught DOMException: Failed to execute 'createElement' on 'Document': The tag name provided 为什么反应 mui 分页组件会导致无法在“文档”上执行“createElement”:提供的标签名称 (“/.js”) 不是有效名称。 错误? - Why react mui pagination component causes Failed to execute 'createElement' on 'Document': The tag name provided ('/.js') is not a valid name. error? React SVG 提供的标签名称无效 - React SVG tag name provided is not valid d3 react js-无法在“文档”上执行“ createElementNS”:提供的限定名称包含无效字符“,” - d3 react js - Failed to execute 'createElementNS' on 'Document': The qualified name provided contains the invalid character ',' React Storybook SVG 无法在“文档”上执行“createElement” - React Storybook SVG Failed to execute 'createElement' on 'Document' 未捕获的 DOMException:无法在“文档”上执行“querySelector”:“不是有效的选择器” - Uncaught DOMException: Failed to execute 'querySelector' on 'Document': '' is not a valid selector
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM