1

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

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

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

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

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

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

我只想使用 jsx 文件。

4

3 回答 3

1

我们遇到了同样的问题。

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

图像1 图像1

于 2016-12-28T13:53:44.893 回答
0

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

于 2016-03-19T04:16:30.173 回答
0

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

于 2015-12-25T22:21:35.003 回答