在写个人项目——扫码点餐中碰到的一些问题
React报错: Objects are not valid as a React Child
解决方法:标签之间的内容不能为对象,不能作为原生元素的子元素,但可以作为自定义组件的子元素
React报错: props is not defined at xxx.render
解决方法:1. render中应写this.state,是否写成了props.state?
Error: Request failed with status code 401
一些前端基础功能部分抛出的错误,promise抛出的错误,不是响应体而是错误对象
向后端请求餐桌信息,跨域问题
后端app.js
1 | app.use(cors({ |
proxy error
proxy代理设置 “proxy”: “http://localhost:5002" 即可
同代表本机的10.1.1就不可以,最好各处写的一致
React脚手架运行npm start报错 webpack版本问题
There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.
The react-scripts package provided by Create React App requires a dependency:
“webpack”: “4.42.0”
Don’t try to install it manually: your package manager does it automatically.
However, a different version of webpack was detected higher up in the tree:
C:\Users\lenovo\node_modules\webpack (version: 4.41.6)
Manually installing incompatible versions is known to cause hard-to-debug issues.
If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.
To fix the dependency tree, try following the steps below in the exact order:
- Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
- Delete node_modules in your project folder.
- Remove “webpack” from dependencies and/or devDependencies in the package.json file in your project folder.
- Run npm install or yarn, depending on the package manager you use.
In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try: - If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
This may help because npm has known issues with package hoisting which may get resolved in future versions. - Check if C:\Users\lenovo\node_modules\webpack is outside your project directory.
For example, you might have accidentally installed something in your home folder. - Try running npm ls webpack in your project folder.
This will tell you which other package (apart from the expected react-scripts) installed webpack.
If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.
P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!
解决办法:在项目文件夹下,新建一个.env文件,在其中写上如下代码:
1 | SKIP_PREFLIGHT_CHECK=true |