每當我嘗試通過將我的應用程式推送到 Heroku 時,git push heroku main都會收到以下錯誤:
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
remote: This is no longer the case. Verify if you need this module and configure a polyfill for it.
remote:
remote: If you want to include a polyfill, you need to:
remote: - add a fallback 'resolve.fallback: { "http": require.resolve("stream-http") }'
remote: - install 'stream-http'
remote: If you don't want to include a polyfill, you can use an empty module like this:
remote: resolve.fallback: { "http": false }
remote:
remote:
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! [email protected] build: `react-scripts build`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the [email protected] build script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
在此錯誤之前,我收到“找不到路徑”或“作業系統”的錯誤,所以我從我的代碼中洗掉了這些匯入,現在它說的是上面所說的內容。好像我什么都做了。
我到達這里的步驟是:
我一直在嘗試通過控制臺將我的應用程式推送到 Heroku,所以我用我為我的專案創建的已經創建的 repo 做了一個 git init。
我做了我的第一次提交,所以執行 heroku 命令可以注意到我的 git 存在。
我已通過以下方式推送到 Heroku:
git push heroku main,git push heroku master,git push heroku HEAD:master,git push heroku HEAD:main --force并且我不斷收到相同的錯誤我嘗試將我的“引擎”添加到 package.json,但這并沒有幫助。
我已經嘗試為這兩個路由添加一個后備到 webpack.config.js,但是,這似乎不起作用。
請幫我解決這個問題。這是我的 index.js、App.js 和 package.json 代碼:
index.js
const express = require('express')
const morgan = require('morgan')
const app = express()
app.use(express.static('build'))
app.use(express.json())
morgan.token("code", function getCode(req) {
return JSON.stringify(req.body);
});
app.use(morgan(':method :url :status :response-time :code'))
let date = new Date('April 18, 2022 07:06:00');
let people = [
{
"id": 1,
"name": "Arto Hellas",
"number": "040-123456"
},
{
"id": 2,
"name": "Ada Lovelace",
"number": "39-44-5323523"
},
{
"id": 3,
"name": "Dan Abramov",
"number": "12-43-234345"
},
{
"id": 4,
"name": "Mary Poppendieck",
"number": "39-23-6423122"
}
]
app.get("/", (req, res) => {
res.send("Landing page")
})
app.get("/api/persons", (req, res) => {
res.status(200).json(people)
})
app.get("/info", (req, res) => {
res.status(200).send(`Phonebook has info for ${people.length} people ${date}`)
})
app.get('/api/persons/:id', (request, response) => {
const id = request.params.id
const person = people.find(person => person.id === Number(id))
response.json(person)
})
app.delete('/api/persons/:id', (request, response) => {
const id = Number(request.params.id)
people = people.filter(person => person.id !== id)
response.status(204).end()
})
app.post('/api/persons', (request, response) => {
let person = {}
const values = Object.values(request.body)
const keys = Object.keys(request.body)
if (!(keys.includes("name"))) return response.status(400).send({error: "A name must be given"})
else if ((people.some(el => el.name === values[0]))) return response.status(406).send({error: "Name must be unique"})
person = {
id: Math.floor(Math.random() * 100 1),
name: values[0],
number: values[1]
}
people = people.concat(person)
response.json(people)
})
const PORT = process.env.PORT || 3001
app.listen(PORT, () => {
console.log(`Listening to port at ${PORT}`)
})
應用程式.js
import logo from './logo.svg';
import './App.css';
function App() {
return (
<div className="App">
</div>
);
}
export default App;
包.json
{
"name": "phonebook",
"version": "0.1.0",
"private": true,
"engines": {
"node": "14.19"
},
"dependencies": {
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.1.1",
"@testing-library/user-event": "^13.5.0",
"express": "^4.17.3",
"morgan": "^1.10.0",
"nodemon": "^2.0.15",
"path-browserify": "^1.0.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-scripts": "5.0.1",
"util": "^0.12.4",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "node ./src/index.js",
"dev": "nodemon index.js",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
檔案
web: npm start
我的目錄圖片

請不要讓我參考另一個堆疊溢位,我已經閱讀并嘗試了這些解決方案,但它們似乎不起作用。我已經嘗試了無數個小時來解決這個問題。
編輯:應用“resolve.fallback {“http”:false}的后備后,它給了我這個額外的錯誤:
Module not found: Error: Can't resolve 'http' in '/tmp/build_c86d77e6/node_modules/express/lib'
如果我想找到這個檔案夾,我在哪里可以找到它?
uj5u.com熱心網友回復:
所以我找到了解決我自己問題的方法。我將 'react-scripts' 從 5.0.1 版更改為 4.0.3 版,然后npm install由于此版本更改,我做了任何更改,并且成功了!我以前做過這一步,但它沒有用,但這次我做了一個npm install修復后的版本更改。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/467616.html
標籤:javascript 节点.js 表示 heroku
上一篇:Herokupipinstall突然開始回傳錯誤:use_2to3isinvalid
下一篇:如何解決discord.py中的以下錯誤:“TypeError__init__()缺少1個必需的僅關鍵字引數:'intents'”
