我正在尝试将我的react应用程序部署在heroku上,但只显示index.html而没有所有组件。该应用程序在localhost上运行正常。我制作了一个form.js用于为nodemailer创建服务器。
我的目录看起来像
src
- index.js
form.js
package.json
我的package.json
{
"name": "earthly",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:3001",
"engines": {
"node": "8.11.1",
"npm": "6.2.0"
},
"dependencies": {
"axios": "^0.18.0",
"body-parser": "^1.18.3",
"concurrently": "^3.6.0",
"data.js": "^0.11.5",
"express": "^4.16.3",
"nodemailer": "^4.6.7",
"nodemon": "^1.18.3",
"npm": "^6.2.0",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-router-dom": "^4.3.1",
"react-scripts": "1.1.4",
"react-stripe-checkout": "^2.6.3",
"react-stripe-elements": "^2.0.1",
"reactstrap": "^6.3.0"
},
"scripts": {
"start": "concurrently \"cross-env NODE_PATH=src react-
scripts start\" \"node index.js\"",
"server": "nodemon form.js",
"dev": "npm run server",
"build": "react-scripts build",
"test": "cross-env NODE_PATH=src react-scripts test --
env=jsdom",
"eject": "react-scripts eject"
},
"devDependencies": {
"cross-env": "^5.2.0"
},
form.js
app.use(express.static(__dirname + '/public'));
app.get('/', function(req, res) {
res.sendFile('index.html');
});
app.listen(process.env.PORT, '0.0.0.0', function(err) {
console.log("Started listening on %s", app.url);
});
在Heroku上构建日志
Node.js app detected
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NODE_VERBOSE=false
NODE_ENV=production
NODE_MODULES_CACHE=true
-----> Installing binaries
engines.node (package.json): 8.11.1
engines.npm (package.json): 6.2.0
Resolving node version 8.11.1...
Downloading and installing node 8.11.1...
Bootstrapping npm 6.2.0 (replacing 5.6.0)...
npm 6.2.0 installed
-----> Restoring cache
Loading 2 from cacheDirectories (default):
- node_modules
- bower_components (not cached - skipping)
-----> Building dependencies
Installing node modules (package.json + package-lock)
audited 21180 packages in 16.791s
found 20 moderate severity vulnerabilities
run `npm audit fix` to fix them, or `npm audit` for
details
-----> Caching build
Clearing previous node cache
Saving 2 cacheDirectories (default):
- node_modules
- bower_components (nothing to cache)
-----> Pruning devDependencies
removed 3 packages and audited 21170 packages in
14.867s
found 20 moderate severity vulnerabilities
run `npm audit fix` to fix them, or `npm audit` for
details
-----> Build succeeded!
-----> Discovering process types
Procfile declares types -> react, web
-----> Compressing...
Done: 62.6M
-----> Launching...
Released v45
https://earthly.herokuapp.com/ deployed to Heroku
我是一名学生,这是我第一次使用react和heroku制作应用程序,所以不知道该怎么做。如果有人可以帮助,将不胜感激!谢谢。