我花了几个小时试图弄清楚这一点,欢迎提出任何建议。这里的目标是组装一个构建后脚本,该脚本将在运行反应客户端的 nodeJS 应用程序上运行。
React 在 3000 后,节点在 5000。所以它需要并发库。以下是两次尝试do-postbuild
和heroku-postbuild
(均失败)。
"scripts": {
"server": "nodemon server.js --ignore client",
"client": "npm start --prefix ../client",
"dev": "concurrently \"npm run server\" \"npm run client\" ",
"do-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix && npm run build --prefix client",
"heroku-postbuild": "cd ../client && npm install && npm install --only=dev --no-shrinkwrap && npm run build"
},
文件夹结构
client
server
|_package.json (above)
|_server.js
npm run dev - 完美
当我尝试npm run heroku-postbuild
它产生以下结果:
npm ERR! errno 1
npm ERR! ver1.02@1.0.0 heroku-postbuild: `cd client && npm install && npm install --only=dev --no-shrinkwrap && npm run build`
npm ERR! Exit status 1
尝试写入时会引发错误,例如在服务器文件夹npm run do-postbuild
中搜索客户端
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/Users/sites/server/client/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent