部署在Azure应用服务上的ReactJS网站引发500错误

时间:2019-09-16 19:06:48

标签: reactjs azure-app-service-envrmnt

我有一个ReactJS应用程序,当将其部署到Azure应用程序服务时会引发500错误,但可以在本地运行。在浏览器的开发工具中,控制台中看不到任何内容,“网络”标签仅显示chrome错误页面的加载。我看到的唯一错误是在Firefox浏览器中,它显示一个错误,指出“未声明纯文本文档的字符编码。”,但我在index.html文件(<meta http-equiv="content-type" content="text/html; charset=utf-8" />)中声明了它。

我不确定确切的位置,但是我在下面包含了webpack.config文件和web.config。如果还有其他需要,我很乐意提供。任何建议都将不胜感激。

编辑: 我能够获得一些天蓝色的日志,并包含以下错误。它说的是意外的标识符,但我认为问题在于它找不到bundle.js文件。在我的index.html中,我目前拥有src =“ / site / wwwroot / dist / bundle.js”,并尝试了其他变体,例如“ /dist/bundle.js”等。再次感谢您的帮助。

webpack.config.js

const path = require(“ path”);

module.exports = {
    mode: 'production',
    entry: path.resolve(__dirname),
    output: {
        path: path.resolve(__dirname,'dist'),
        filename: 'bundle.js',
        publicPath: '/',
    },
    resolve: {
        extensions: ['.js','.jsx','.*']
    },
    devServer: {
        historyApiFallback: true
    },
    module: {
        rules: [
            {
            test: /\.jsx?/,
            loader:'babel-loader'},
            {
                test: /\.css$/,
                use: ['style-loader', 'css-loader']
            },
            {test: /\.(jpe?g|png|gif|svg)$/i, loader: "url-loader?name=app/images/[name].[ext]"},
            { 
                test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, 
                loader: "url-loader?limit=10000&mimetype=application/font-woff" 
            },
            { 
                test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, 
                loader: "file-loader" 
            },
            {
                test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/i,
                use: [{
                  loader: 'url-loader',
                  options: {
                    fallback: {
                      loader: 'file-loader',
                    }
                  }
                }]
              },
        ]
    }
}

web.config

<?xml version="1.0" encoding="utf-8"?>
<!--
     This configuration file is required if iisnode is used to run node processes behind
     IIS or IIS Express.  For more information, visit:

     https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config
-->

<configuration>
  <system.webServer>
    <!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support -->
    <webSocket enabled="false" />
    <handlers>
      <!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
      <add name="iisnode" path="index.html" verb="*" modules="iisnode"/>
    </handlers>
    <rewrite>
      <rules>
        <!-- Do not interfere with requests for node-inspector debugging -->
        <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^index.html\/debug[\/]?" />
        </rule>

        <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
        <rule name="StaticContent">
          <action type="Rewrite" url="public{PATH_INFO}"/>
        </rule>

        <!-- All other URLs are mapped to the node.js site entry point -->
        <rule name="DynamicContent">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
          </conditions>
          <action type="Rewrite" url="index.html"/>
        </rule>
      </rules>
    </rewrite>

    <!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
    <security>
      <requestFiltering>
        <hiddenSegments>
          <remove segment="bin"/>
        </hiddenSegments>
      </requestFiltering>
    </security>

    <!-- Make sure error responses are left untouched -->
    <httpErrors existingResponse="PassThrough" />

    <!--
      You can control how Node is hosted within IIS using the following options:
        * watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
        * node_env: will be propagated to node as NODE_ENV environment variable
        * debuggingEnabled - controls whether the built-in debugger is enabled

      See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
    -->
    <!--<iisnode watchedFiles="web.config;*.js"/>-->
  </system.webServer>
</configuration>

日志流

Tue Sep 10 2019 13:36:56 GMT+0000 (Coordinated Universal Time): Application has thrown an uncaught exception and is terminated:
D:\home\site\wwwroot\myclient\index.html:1
(function (exports, require, module, __filename, __dirname) { <meta http-equiv="content-type" content="text/html; charset=utf-8" />
                                                              ^

SyntaxError: Unexpected token <
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:607:28)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Module.require (module.js:587:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (D:\Program Files (x86)\iisnode\interceptor.js:459:1)
Tue Sep 10 2019 13:37:09 GMT+0000 (Coordinated Universal Time): Application has thrown an uncaught exception and is terminated:
D:\home\site\wwwroot\myclient\index.html:1
(function (exports, require, module, __filename, __dirname) { <meta http-equiv="content-type" content="text/html; charset=utf-8" />
                                                              ^

SyntaxError: Unexpected token <
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:607:28)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Module.require (module.js:587:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (D:\Program Files (x86)\iisnode\interceptor.js:459:1)

0 个答案:

没有答案