Jas*_*der 5 deployment module heroku reactjs
我正在尝试将我的应用程序部署到 Heroku,它可以在本地运行,但在网上没有运气。我删除并重新安装了节点模块。
我有另一个与此非常相关的错误(未找到相同名称的文件等)我更改了相对路径,认为可以解决问题,但我没有得到任何结果
错误是:
找不到文件“./Components/SearchBar/SearchBar”
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import SearchBar from './Components/SearchBar/SearchBar'
import BusinessList from './Components/BusinessList/BusinessList'
import Business from './Components/Business/Business'
import Yelp from './Components/Util/Yelp'
Run Code Online (Sandbox Code Playgroud)
我希望不会因为如此简单的事情而引发错误,我已经倾注了文件和文件夹名称,但它只是没有意义。
PS 我认为它可能未连接我有 const yelpApiKey=process.env.yelpApiKey 供我的 heroku 连接到我的 API 密钥(在我的帐户中输入)
感谢@Jason 提出这个问题,感谢@Rakesh 的回答。
我在 Heroku 上部署了create-react-app项目,然后遇到了类似的错误,无法构建我的项目。错误是routes.js无法导入signup.js
Heroku 日志
-----> Node.js app detected
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NODE_ENV=production
NODE_MODULES_CACHE=false
NODE_VERBOSE=false
-----> Installing binaries
engines.node (package.json): 10.16.3
engines.npm (package.json): unspecified (use default)
Resolving node version 10.16.3...
Downloading and installing node 10.16.3...
Using default npm version: 6.9.0
-----> Restoring cache
Caching has been disabled because NODE_MODULES_CACHE=false
-----> Installing dependencies
Installing node modules (package.json + package-lock)
> core-js@2.6.9 postinstall /tmp/build_5d506b6dfc93b7f4b6575e02cc682130/node_modules/babel-runtime/node_modules/core-js
> node scripts/postinstall || echo "ignore"
> core-js@3.2.1 postinstall /tmp/build_5d506b6dfc93b7f4b6575e02cc682130/node_modules/core-js
> node scripts/postinstall || echo "ignore"
added 1507 packages from 719 contributors and audited 905071 packages in 35.746s
found 0 vulnerabilities
-----> Build
Running build
> chat-app@0.1.0 build /tmp/build_5d506b6dfc93b7f4b6575e02cc682130
> react-scripts build
Creating an optimized production build...
Failed to compile.
./src/routes.js // my beautiful error here
Cannot find file './Components/User/signup/signup.js' in './src'.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! chat-app@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the chat-app@0.1.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! /tmp/npmcache.ynm0W/_logs/2019-09-30T15_24_32_571Z-debug.log
-----> Build failed
We're sorry this build is failing! You can troubleshoot common issues here:
https://devcenter.heroku.com/articles/troubleshooting-node-deploys
If you're stuck, please submit a ticket so we can help:
https://help.heroku.com/
Love,
Heroku
! Push rejected, failed to compile Node.js app.
! Push failed
Run Code Online (Sandbox Code Playgroud)
Heroku 在 Linux 服务器上部署项目,这意味着如果您犯了错误,构建将失败,则区分大小写。我建议在命名文件和目录时坚持使用小写字母。
my project structure
|root
|src
| componets
| user
| signup
|routes
|index.js
Run Code Online (Sandbox Code Playgroud)
在我纠正错误后,我仍然有同样的错误。所以为什么?我没有注意到 Git 没有推送更改。当您只重命名目录时,即使您执行git add、git commit和git push , Git 有时也不会考虑更改。我建议更改后去网站验证。
部署到 Heroku 时,请仅部署基本分支。例如Master或develop。我意识到每次部署我的功能分支时,Heroku 都会自动检测我的基础分支,即develop。
我发现你的代码有两个问题:
在index.js 中导入“App”是错误的。使用以下
import App from './App';
Run Code Online (Sandbox Code Playgroud)