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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/54003685/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 05:45:30  来源:igfitidea点击:

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

reactjstypescript

提问by Red Baron

I have a react app that I am trying to convert to use typescript

我有一个 React 应用程序,我正在尝试将其转换为使用打字稿

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?

任何想法如何解决?

回答by Ming

In my case, I was building my web app and I created a javaScript file in the IDE IntelliJ, everything is fine there. but in the folder, the suffix ".js" is missing, so when I use 'npm run dev' command in there terminal, it failed to find the file I built.

就我而言,我正在构建我的 Web 应用程序,并在 IDE IntelliJ 中创建了一个 javaScript 文件,那里一切正常。但是在文件夹中,缺少后缀“.js”,所以当我在终端中使用“npm run dev”命令时,它无法找到我构建的文件。

If it is the same for you, then just go to the fold and add the suffix . then solved

如果它对你来说是一样的,那么就去折叠并添加后缀。然后解决了

I think it's a bug in IntelliJ, Hopefully they may fix it later on.

我认为这是 IntelliJ 中的一个错误,希望他们以后可以修复它。

回答by Sachit Shetty

The problem for me was that I was trying to render ts files. React can't 'create elements' from ts files. TS files need to be transpiled to JS. I thought that my babel loader was configured correctly but it wasn't. The babel loader wasn't checking for ts or tsx files.

我的问题是我试图渲染 ts 文件。React 无法从 ts 文件“创建元素”。TS 文件需要转译为 JS。我以为我的 babel loader 配置正确,但事实并非如此。babel 加载器没有检查 ts 或 tsx 文件。

回答by Karan Pardeshi

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.

" 为其添加适当的扩展名或将其删除。

回答by shanzi

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

回答by tksilicon

I got this error. It happened that the name of the js folder had spaces at the end of it. Seems React doesn't recognise space in folder/file names.

我收到了这个错误。碰巧js文件夹的名字后面有空格。似乎 React 无法识别文件夹/文件名中的空格。

回答by Russell D

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 } />

回答by Morespurs

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.

注意引号。希望这可以帮助某人。

回答by Ivan Panasyuk

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". 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!

对我来说,没有正确扩展名的文件是一个简单的错误(正如有人已经提到的那样)。就我而言,它是 SearchBox 子项,它被保存为文本文件,而不是“SearchBox.js”。在您的情况下,它将是“索引”文件。当然,我对此完全陌生并且仍在学习,只是想我会分享,因为阅读以前对您的问题的回答帮助我解决了我的问题!

回答by T.J. Crowder

It means you have code trying to do this:

这意味着您有代码尝试执行此操作:

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

...directly or indirectly. Since /static/media/index.c6592bb6.tsisn't a valid tag name (like divor span), it fails.

...直接或间接。由于/static/media/index.c6592bb6.ts不是有效的标记名称(如divspan),因此失败。