Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Heroku上的MERN不能跨浏览器工作_Node.js_Reactjs_Heroku_Deployment_Mern - Fatal编程技术网

Node.js Heroku上的MERN不能跨浏览器工作

Node.js Heroku上的MERN不能跨浏览器工作,node.js,reactjs,heroku,deployment,mern,Node.js,Reactjs,Heroku,Deployment,Mern,我用MLab、React、Redux开发了MERN应用程序在dev中工作正常。 我在Heroku中部署,在用于开发的Chrome中运行良好(带有React、Redux附件) 问题:它在我的机器的任何其他浏览器中显示为空白,包括在任何其他机器的chrome浏览器中。我在网上查了一下,根据这个论坛上的一个解决方案,我在server.js(或app.js)上做了如下操作。也就是说,在我自己的chrome浏览器中,这个URL()可以正常工作,但在任何其他浏览器中,它都是一个空白页面 if (proces

我用MLab、React、Redux开发了MERN应用程序在dev中工作正常。 我在Heroku中部署,在用于开发的Chrome中运行良好(带有React、Redux附件)

问题:它在我的机器的任何其他浏览器中显示为空白,包括在任何其他机器的chrome浏览器中。我在网上查了一下,根据这个论坛上的一个解决方案,我在server.js(或app.js)上做了如下操作。也就是说,在我自己的chrome浏览器中,这个URL()可以正常工作,但在任何其他浏览器中,它都是一个空白页面

if (process.env.NODE_ENV === 'production') {
        // app.use(express.static('client/build')); returns blank page
        // Changed to ...
        app.use('/static', express.static(path.join(__dirname, 'client/build')));
        app.get('*', (req, res) => {
        res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
      });
    }
传统的。。。git stuff(git add,commit)然后检查与Heroku的远程连接,并执行“git push Heroku master”。一切都很好。。。服务器已启动并正在运行。再一次,它出现在我的chrome中,像一个魔咒一样工作。。。但没有别的地方

以下是我的服务器端package.json:

    {
      "name": "appname",
      "version": "1.0.0",
      "description": "Developer Connection social media",
      "main": "server.js",
      "scripts": {
      "client-install": "npm install --prefix client",
      "start": "node server.js",
      "server": "nodemon server.js",
      "client": "npm start -prefix client",
      "dev": "concurrently \"npm run server\" \"npm run client\"",
      "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix 
 client && npm run build --prefix client"
  },
      "author": "Jit <sarbojit.project@gmail.com>",
      "license": "ISC",
      "dependencies": {
      "bcryptjs": "^2.4.3",
      "body-parser": "^1.18.3",
      "concurrently": "^3.6.0",
      "express": "^4.16.3",
      "gravatar": "^1.6.0",
      "jsonwebtoken": "^8.3.0",
      "mongoose": "^5.1.5",
      "passport": "^0.4.0",
      "passport-jwt": "^4.0.0",
      "validator": "^10.3.0"
     }
}
我的目录结构:

appName
  client
    public 
      ... index.html (that is the root of react)
    src
      ... this has all the react code
  package.json (client side)
....... SERVER SIDE  
server.js
models  
   ... all models here
routers
   ... all routers here
validations
   ... all validations here
package.json   (SERVER SIDE)
.gitignore
正在尝试遵循以下指令:


任何帮助

为了让Heroku进行渲染,如果您碰巧在chrome中添加了REDUX开发工具进行开发,请执行以下操作:

const store=createStore( 减根剂, 初始状态, 谱写( applyMiddleware(…中间件), //窗口。REDUX\u开发工具扩展&窗口。REDUX\u开发工具扩展() //检查下一步是否有效 窗口。REDUX\u DEVTOOLS\u扩展 ?窗口。REDUX\u DEVTOOLS\u扩展 :f=>f ) );


最初,我强迫chrome添加DEVTOOL(如上所述,现在由Trialum替换)。Heroku在构建时并没有忽略这一点,也没有产生错误甚至警告。它只是没有呈现(空白)。在上述场景中,这将呈现页面

尝试加载应用程序时,控制台中出现语法错误。清除dev机器上的缓存,看看它是否仍然正常工作。然后找出那个语法错误是什么。
appName
  client
    public 
      ... index.html (that is the root of react)
    src
      ... this has all the react code
  package.json (client side)
....... SERVER SIDE  
server.js
models  
   ... all models here
routers
   ... all routers here
validations
   ... all validations here
package.json   (SERVER SIDE)
.gitignore