首页 > 解决方案 > 尝试在本地主机上创建的 Netlify 上部署我的反应应用程序,但在尝试部署时出错

问题描述

我已经在我的本地主机上创建了一个反应应用程序并将其推送到我的 github 存储库中,但是现在我想在 Netlify 上部署它,我得到了这个错误。这是包含一些错误的日志的一部分。plzzzzzzzz 帮帮我:(。顺便说一句,代码在本地主机上运行顺利。

7:50:52 PM:   1. Build command from Netlify app                             
7:50:52 PM: ────────────────────────────────────────────────────────────────
7:50:52 PM: ​
7:50:52 PM: $ npm run build
7:50:52 PM: > project@0.1.0 build /opt/build/repo
7:50:52 PM: > react-scripts build
7:50:54 PM: Creating an optimized production build...
7:50:56 PM: Failed to compile.
7:50:56 PM: 
7:50:56 PM: ./src/App.js
7:50:56 PM: Cannot find module: 'react-router-dom'. Make sure this package is installed.
7:50:56 PM: You can install this package by running: yarn add react-router-dom.
7:50:56 PM: npm ERR! code ELIFECYCLE
7:50:56 PM: npm ERR! errno 1
7:50:56 PM: npm ERR! project@0.1.0 build: `react-scripts build`
7:50:56 PM: npm ERR! Exit status 1
7:50:56 PM: npm ERR!
7:50:56 PM: npm ERR! Failed at the project@0.1.0 build script.
7:50:56 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
7:50:56 PM: npm ERR! A complete log of this run can be found in:
7:50:56 PM: npm ERR!     /opt/buildhome/.npm/_logs/2021-07-08T15_20_56_695Z-debug.log
7:50:56 PM: ​
7:50:56 PM: ────────────────────────────────────────────────────────────────
7:50:56 PM:   "build.command" failed                                        
7:50:56 PM: ────────────────────────────────────────────────────────────────
7:50:56 PM: ​
7:50:56 PM:   Error message
7:50:56 PM:   Command failed with exit code 1: npm run build
7:50:56 PM: ​
7:50:56 PM:   Error location
7:50:56 PM:   In Build command from Netlify app:
7:50:56 PM:   npm run build
7:50:56 PM: ​
7:50:56 PM:   Resolved config
7:50:56 PM:   build:
7:50:56 PM:     command: npm run build
7:50:56 PM:     commandOrigin: ui
7:50:56 PM:     publish: /opt/build/repo/build
7:50:56 PM:     publishOrigin: ui
7:50:56 PM:   functions:
7:50:56 PM:     '*': {}
7:50:57 PM: Caching artifacts
7:50:57 PM: Started saving node modules
7:50:57 PM: Finished saving node modules
7:50:57 PM: Started saving build plugins
7:50:57 PM: Finished saving build plugins
7:50:57 PM: Started saving yarn cache
7:50:57 PM: Finished saving yarn cache
7:50:57 PM: Started saving pip cache
7:50:57 PM: Finished saving pip cache
7:50:57 PM: Started saving emacs cask dependencies
7:50:57 PM: Finished saving emacs cask dependencies
7:50:57 PM: Started saving maven dependencies
7:50:57 PM: Finished saving maven dependencies
7:50:57 PM: Started saving boot dependencies
7:50:57 PM: Finished saving boot dependencies
7:50:57 PM: Started saving rust rustup cache
7:50:57 PM: Finished saving rust rustup cache
7:50:57 PM: Started saving go dependencies
7:50:57 PM: Finished saving go dependencies
7:51:00 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
7:51:00 PM: Creating deploy upload records
7:51:00 PM: Failing build: Failed to build site
7:51:00 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
7:51:00 PM: Finished processing build request in 54.583388691s

标签: javascriptreactjsnetlify

解决方案


只需阅读您拥有的错误日志:

 Cannot find module: 'react-router-dom'. Make sure this package is installed.
7:50:56 PM: You can install this package by running: yarn add react-router-dom.

确保你的 package.json 文件中有“react-router-dom”。

运行:yarn add react-router-dom在您的控制台中。


推荐阅读