Visual Studio 2012 Express:浏览器返回 500 状态,尝试下载 jsx 文件

Visual Studio 2012 Express: Browser returning 500 status trying to download jsx file

我正在学习本教程:http://reactjs.net/getting-started/tutorial.html 并使用 Visual Studio 2012 Express。

<body>
    <script src="@Url.Content("~/Scripts/Tutorial.jsx")"></script>
</body>

我在同一个项目的 Scripts 文件夹中有 Tutorial.jsx 我仍然在 google chrome.

的控制台中收到 500 状态错误

但是当我尝试将其更改为:

<body>
    <script src="~/Scripts/Tutorial.js"></script>
</body>

Tutorial.js 也在 Scripts 文件夹中,chrome 下载它并且工作正常。

我只想使用 jsx 文件。

为了通过您提到的第一个示例获取 jsx 文件,该文件不起作用,您必须将该文件放在正确的文件夹中,如此处所示。

JSX 文件的位置

通常;但是,500 错误可能意味着其他地方出了问题。打开你的项目并确认你有这些包.. 在 packages.config 文件中找到。

需要的包

终于 该项目需要创建为空 MVC 项目 个 MVC 文件夹。这允许您创建控制器来提供索引文件。

索引文件

 @{
        Layout = null;
    }
    <html>
    <head>
        <title>Hello React</title>
    </head>
    <body>
        <div id="content"></div>
        <script src="https://fb.me/react-0.14.0.min.js"></script>
        <script src="https://fb.me/react-dom-0.14.0.min.js"></script>
        <script src="@Url.Content("~/Scripts/Tutorial.jsx")"></script>
    </body>
    </html>

家庭控制器

public class HomeController : Controller
{
    // GET: Home
    public ActionResult Index()
    {
        return View();
    }
}

调试中

导航到该页面,按 F12,按控制台按钮,查看是否有任何错误。

我想我遇到了同样的问题。每当我点击我的 .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 中一定有我忘记设置的设置或其他内容,或者可能忘记注释掉。

我们遇到了同样的问题。

我们解决了我们的问题,将 .jsx 文件的 构建操作 属性 从 none 更改为 content