简体   繁体   English

尝试将 MERN 应用程序部署到 Now (zeit.co) 时出现“sh: react-scripts: command not found”错误

[英]Getting 'sh: react-scripts: command not found' error when trying to deploy MERN app to Now (zeit.co)

I am trying to deploy a MERN app to Now(zeit.co) with no success.我正在尝试将一个 MERN 应用程序部署到 Now(zeit.co),但没有成功。 When Now tries to build during deployment, it gets a 'sh: react-scripts: command not found' error and logs the following:当 Now 在部署期间尝试构建时,它会收到“sh: react-scripts: command not found”错误并记录以下内容:

Downloading 56 deployment files...
Installing build runtime...
Build runtime installed: 422.936ms
Looking up build cache...
Installing dependencies...
> nodemon@2.0.2 postinstall /zeit/3a1e3f7b/node_modules/nodemon
> node bin/postinstall || exit 0
Love nodemon? You can now support the project via the open collective:
 > https://opencollective.com/nodemon/donate
npm WARN debts-app-api@1.0.0 No description
npm WARN debts-app-api@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.2 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 188 packages from 92 contributors in 2.415s
Running "npm run build"
> debts-app-api@1.0.0 build /zeit/3a1e3f7b
> npm run build --prefix client
> client@0.1.0 build /zeit/3a1e3f7b/client
> react-scripts build
sh: react-scripts: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! client@0.1.0 build: `react-scripts build`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the client@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR!     /zeit/.npm/_logs/2020-01-04T20_32_03_150Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! debts-app-api@1.0.0 build: `npm run build --prefix client`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the debts-app-api@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /zeit/.npm/_logs/2020-01-04T20_32_03_163Z-debug.log
Error: Exited with 1
    at ChildProcess.child.on (/zeit/69d347bcc38c1970/.build-utils/.builder/node_modules/@now/static-build/dist/index.js:32747:24)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
worker exited with code 20 and signal null
done

My app's architecture is:我的应用程序的架构是:

应用架构

I created the app with npm, using npx create-react-app client --use-npm to create the React client, so I don't believe it to be a conflict between yarn and npm.我用npm创建了app,使用npx create-react-app client --use-npm来创建React客户端,所以我不认为是yarn和npm的冲突。

My server package.json is:我的服务器package.json是:

{
  (...)
  "scripts": {
    "start": "node index.js",
    "server": "nodemon index.js",
    "client": "npm run start --prefix client",
    "dev": "concurrently \"npm run server\" \"npm run client\"",
    "build": "npm run build --prefix client"
  },
  (...)
  }
}

My client/package.json is the default for create-react-app:我的client/package.json是 create-react-app 的默认值:

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.4.0",
    "@testing-library/user-event": "^7.2.1",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-scripts": "3.3.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

Just to make sure, I tried running npm install on my client folder, but it didn't do much.只是为了确保,我尝试在我的客户端文件夹上运行npm install ,但它没有做太多。 I checked my package-lock.json and, sure thing, react-scripts is there, so I expect it should also show up when Now tries to build from the github repo, right?我检查了我的 package-lock.json,可以肯定的是,react-scripts 在那里,所以我希望当 Now 尝试从 github repo 构建时,它也应该显示出来,对吗? I also took a look on my client/.gitignore , but it is just the default file for create-react-app:我还查看了我的client/.gitignore ,但它只是 create-react-app 的默认文件:

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

My server's .gitignore file also has nothing that could be causing the problem, it's only ignoring node_modules and .env.我的服务器的.gitignore文件也没有任何可能导致问题的内容,它只是忽略了 node_modules 和 .env。

If anybody with more experience deploying MERN apps could help me, I would be very grateful.如果有更多部署 MERN 应用程序经验的人可以帮助我,我将不胜感激。

If anyone is having the same trouble, I had an insight.如果有人遇到同样的麻烦,我有一个洞察力。 A simple solution was to change the server's package.json build script to:一个简单的解决方案是将服务器的package.json构建脚本更改为:

"build": "npm install --prefix client && npm run build --prefix client"

What was causing the problem is that Now(zeit.co) was building the dependencies for the server, which was at the root of the app folder, but wasn't building dependencies for the client folder.导致问题的原因是 Now(zeit.co) 正在为服务器构建依赖项,它位于 app 文件夹的根目录,但没有为客户端文件夹构建依赖项。

It would run the script "build": "npm run build --prefix client" , found on root/package.json .它将运行脚本"build": "npm run build --prefix client" ,在root/package.json上找到。 That redirects it to run the root/client/package.json scripts, ie it would try to run the script "build": "react-scripts build" and collapse because it couldn't find react-scripts.这会将它重定向到运行root/client/package.json脚本,即它会尝试运行脚本"build": "react-scripts build"并崩溃,因为它找不到 react-scripts。

Making the aforementioned change, it now installs the client dependencies before trying to run "build": "react-scripts build"进行上述更改,它现在会在尝试运行"build": "react-scripts build"之前安装客户端依赖项"build": "react-scripts build"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 npm start throws sh: react-scripts: command not found - npm start throws sh: react-scripts: command not found 尝试通过 now 部署到 Vercel(Zeit) 时,docusaurus 出现部署错误 - Deployment error with docusaurus when trying to deploy via now to Vercel(Zeit) 尝试将我的应用程序(Node,React,Socketio)部署到Heroku会给我“ sh:1:react-scripts:权限被拒绝” - Attempting to deploy my app (Node, React, Socketio) to Heroku gives me “sh: 1: react-scripts: Permission denied” 由于这个“远程:sh:1:react-scripts:权限被拒绝错误”,正在努力将我的反应项目部署到 heroku - Struggling to deploy my react project to heroku due to this `remote: sh: 1: react-scripts: Permission denied error` 反应脚本:找不到命令(npm start) - react-scripts: command not found (npm start) 运行“npm run build”后“sh: 1: react-scripts: not found” - "sh: 1: react-scripts: not found" after running "npm run build" 如何修复错误:SQLITE_CANTOPEN:无法在 Zeit.co 上打开数据库? - How to fix Error: SQLITE_CANTOPEN: unable to open database on Zeit.co? react-scripts:在ubuntu的create-react-app项目上找不到? - react-scripts: not found on create-react-app project on ubuntu? 尝试将 React/Redux 应用程序部署到 Heroku……现在我收到 R14 memory 错误 - Trying to deploy a React/Redux app to Heroku…now I'm getting an R14 memory error sh:react-scripts-start:找不到命令 - sh: react-scripts-start: command not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM