我试图推送到 git,但我的文件太大了。尝试删除 node_modules 文件夹,然后运行 npm start 但现在我收到此错误:
Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.allowedHosts[0] should be a non-empty string.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start 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:
我尝试重新安装nodemon(这对其他人有效)。还尝试运行 npm run start 但错误仍然存在。我也尝试过使用 node_modules 文件夹的备份版本,但错误是相同的。
参见下面的package.json。这是针对客户端的。
{
"name": "dlfrontend",
"version": "0.1.0",
"proxy": "http://localhost:3000",
"private": true,
"dependencies": {
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@fortawesome/fontawesome-svg-core": "^6.4.2",
"@fortawesome/free-solid-svg-icons": "^6.4.2",
"@fortawesome/react-fontawesome": "^0.2.0",
"@mui/material": "^5.14.3",
"@mui/styled-engine-sc": "^5.12.0",
"@mui/x-data-grid": "^6.10.2",
"@syncfusion/ej2-react-filemanager": "^22.2.5",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.4.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-dropzone": "^14.2.3",
"react-router-dom": "^6.14.2",
"react-scripts": "5.0.1",
"react-toastify": "^9.1.3",
"styled-components": "^5.3.11",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"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"
]
}
}
您的项目似乎正在使用 CRA。尽管它仍然有效,但 React-Team 已声明它已弃用,我建议您切换编译器:
停止使用 CRA,使用 Vite 来创建你的 React 应用程序。
npm create vite@latest
按照提示操作。与 CRA 相比,它的重量更轻。