【问题标题】:How to solve Unable to resolve type: React.ReactEnvironment Exception如何解决无法解析类型:React.ReactEnvironment Exception
【发布时间】:2017-08-10 04:25:43
【问题描述】:

我收到以下错误:

 Unable to resolve type: React.ReactEnvironment

内部异常:

Unable to resolve type: React.JavaScriptEngineFactory

内部异常:

Object doesn't support this property or method

这是 Application_Start

   AreaRegistration.RegisterAllAreas();
   RouteConfig.RegisterRoutes(RouteTable.Routes);
   BundleConfig.RegisterBundles(BundleTable.Bundles);

这是 BundleConfig.RegisterBundles

   bundles.Add(new BabelBundle("~/bundles").Include("~/Scripts/HelloWorld.jsx"));

这是主页/索引视图

@{
    ViewBag.Title = "Index";
}

    <script src="~/Scripts/react/react.min.js"></script>
    <script src="~/Scripts/react/react-dom.min.js"></script>

@Scripts.Render("~/bundles")
<div id="content"></div>

错误发生在这一行

 @Scripts.Render("~/bundles")

更新1 当我尝试直接在浏览器中访问 /Scripts/HelloWorld.jsx 时,我收到了以下服务器错误消息:

MsieJavaScriptEngine.JsRuntimeException: Object doesn't support this property or method

【问题讨论】:

标签: c# asp.net reactjs asp.net-mvc-5 reactjs.net


【解决方案1】:

我们应该创建一个静态 ReactConfig 类并使用所有 .jsx 文件配置 ReactSiteConfiguration。

我们应该将我们的 .jsx 文件添加到脚本中,如下所示

    public static class ReactConfig
    {
       public static void Configure()
       {
          ReactSiteConfiguration.Configuration
            .AddScript("~/Scripts/HelloWorld.jsx");
       }
    }

在 Application_start 调用中

RouteConfig.Configure();

【讨论】:

  • 我按照您的建议添加了ReactConfig 类,然后我在Application_Start() 中调用了RouteConfig.Configure(),但错误仍然存​​在
  • 尝试在@script.Render 下方的视图中调用@Html.ReactInitJavaScript()
  • 但是,为什么是间接的?它有什么用途?
猜你喜欢
  • 2020-09-11
  • 1970-01-01
  • 2020-03-26
  • 1970-01-01
  • 2017-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-22
相关资源
最近更新 更多