我想我有同样的问题。每当我点击我的 .jsx 文件时,我都会收到 500 错误。通过终端我可以看到这是通过 React/Babel 加载器的错误。无论出于何种原因,传递给函数的路径是:
/path/that/contains/scriptfolder/path/that/contains/scriptfolder/Scripts/1.jsx
这对我来说没有多大意义,这是输出:
Request starting HTTP/1.1 GET http://localhost:5000/Scripts/HelloWorld.jsx
fail: Microsoft.AspNet.Diagnostics.ExceptionHandlerMiddleware[0]
An unhandled exception has occurred: Could not find a part of the path
"/home/pete/code/ReactExample/wwwroot/home/pete/code/ReactExample/wwwroot
/Scripts/HelloWorld.jsx".
System.IO.DirectoryNotFoundException: Could not find a part of the path
"/home/pete/code/ReactExample/wwwroot/home/pete/code/ReactExample/wwwroot
/Scripts/HelloWorld.jsx".
所以它显然无法找到该文件,因为它使用了一个愚蠢的路径。这直接来自 React 代码:
at System.IO.StreamReader..ctor (System.String path, System.Text.Encoding encoding)
<0x7fcead751600 + 0x00031> in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.IO.StreamReader:.ctor (string,
System.Text.Encoding)
at System.IO.File.ReadAllText (System.String path, System.Text.Encoding
encoding) <0x7fcead8e0610 + 0x0003b> in <filename unknown>:0
at React.FileSystemBase.ReadAsString (System.String relativePath)
<0x4027ffb0 + 0x0003f> in <filename unknown>:0
at React.Babel.TransformFileWithSourceMap (System.String filename,
Boolean forceGenerateSourceMap) <0x403d45c0 + 0x000d5> in <filename unknown>:0
at React.Babel.TransformFile (System.String filename) <0x403d4590 + 0x0001a>
in <filename unknown>:0
at React.AspNet.BabelFileSystem+BabelFileInfo+<>c__DisplayClass3_0.<.ctor>
b__0 () <0x403d4510 + 0x0005e> in <filename unknown>:0
现在至于它为什么这样做,我不知道。我知道这不是 Web 容器,因为那里还有一个文件 hello.html,它已成功发送回浏览器。Startup.cs 中一定有我忘记设置的设置或某些内容,或者可能忘记注释掉。