我试图在Netlify上设置持续部署。我已经链接了我的Github帐户,所以我现在需要设置我的构建命令:
复杂的是我的build.json和build命令(来自create-react-app)不在项目根目录中。相反,它的1个文件夹就像这样:
react // this is a folder
-package.json // has build commands for React
server // this is a folder
-package.json // has build commands for my backend as a service
由于我使用后端作为服务,因此我不需要在服务器中使用任何服务器'文件夹部署到Netlify,只是反应'反应'文件夹中。
我可以从项目根目录中运行react / package.json中的命令吗?
在我的本地计算机上,我可以使用以下命令从root运行build命令:
{
"scripts": {
"netlify": "cd ./react && npm run build"
}
}
但在Netlify上它出错:
9:56:31 AM: Executing user command: npm run netlify
9:56:31 AM: > @ netlify /opt/build/repo
9:56:31 AM: > cd ./react && npm run build
9:56:32 AM: > testproject@0.0.1 build /opt/build/repo/react
9:56:32 AM: > npm-run-all build-css build-js
9:56:32 AM: sh: 1: npm-run-all: not found
9:56:32 AM: npm ERR! file sh
9:56:32 AM: npm ERR! code ELIFECYCLE
9:56:32 AM: npm ERR! errno ENOENT
9:56:32 AM: npm ERR! syscall spawn
9:56:32 AM: npm ERR! testproject@0.0.1 build: `npm-run-all build-css build-js`
9:56:32 AM: npm ERR! spawn ENOENT
9:56:32 AM: npm ERR!
9:56:32 AM: npm ERR! Failed at the testproject@0.0.1 build script.
9:56:32 AM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
9:56:32 AM: npm WARN Local package.json exists, but node_modules missing, did you mean to install?
9:56:32 AM: npm ERR! A complete log of this run can be found in:
9:56:32 AM: npm ERR! /opt/buildhome/.npm/_logs/2018-03-01T02_56_32_022Z-debug.log
9:56:32 AM: npm ERR! code ELIFECYCLE
9:56:32 AM: npm ERR! errno 1
9:56:32 AM: npm ERR! @ netlify: `cd ./react && npm run build`
9:56:32 AM: npm ERR! Exit status 1
答案 0 :(得分:3)
免责声明:我为Netlify工作
如果有/package.json,我们的构建过程将只为你'npm install'。我认为您可以使用此构建命令成功构建:
cd ./react && npm install && npm run build
...假设你在package.json中有npm-run-all
:)
然而,这不是解决问题的最佳方法。最佳做法是使用netlify.toml
file为您的构建设置base
。我们将在开始构建之前cd到这个目录,然后我们只需拿起你的package.json并自动安装,这样你的构建命令就会简化为npm run build
,以及任何克隆你的repo的人也将在Netlify上成功建立:)
[build]
base = "react"
...就是那个文件中你需要的一切。