【问题标题】:Visual Studio 2012 Express: Browser returning 500 status trying to download jsx fileVisual Studio 2012 Express:浏览器返回 500 状态尝试下载 jsx 文件
【发布时间】:2015-12-19 09:17:44
【问题描述】:

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

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

我在同一个项目的Scripts 文件夹中有Tutorial.jsx,但我在谷歌浏览器的控制台中仍然收到 500 状态错误。

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

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

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

我只想使用 jsx 文件。

【问题讨论】:

  • 你能分享一下确切的错误吗?我认为这是一个 mime 类型的问题。
  • localhost:51175/Scripts/Tutorial.jsx 加载资源失败:服务器响应状态为 500(内部服务器错误)
  • 我很确定我遇到了同样的问题。由于某种原因,jsx 路径实际上被解析为 /username/some_folder/wwwroot/username/some_folder/wwwroot/tutorial.jsx,我会回复。

标签: reactjs reactjs.net


【解决方案1】:

我们遇到了同样的问题。

我们解决了将 .jsx 文件的 build action 属性从 none 更改为 content

的问题

【讨论】:

    【解决方案2】:

    为了通过您提到的第一个示例获取 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,按控制台按钮并查看是否有任何错误。

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多