报错:

目录

1、xxx: 无法加载文件 C:\Users\Administrator\AppData\Roaming\npm\xxx.ps1,因为在此系统上禁止运行 脚本。
2、npm install 报错 cb.apply is not a function
3、npm install报错npm ERR! Maximum call stack size exceeded
4、Warning: Received true for a non-boolean attribute div.If you want to write it to the DOM, pass a string instead: div="true" or div={value.toString()}.
5、Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
6、Warning: Expected ProcessSelect state to match memoized state before processing the update queue. This might either be because of a bug in React, or because a component reassigns its own this.state. Please file an issue.
7、Useless constructor no-useless-constructor
8、Support for the experimental syntax 'decorators-legacy' isn't currently enabled

正文

1、xxx: 无法加载文件 C:\Users\Administrator\AppData\Roaming\npm\xxx.ps1,因为在此系统上禁止运行 脚本。
1.png

解决:

以管理员身份运行powerShell(一定要以管路员身份打开):
2.png
命令行:
set-ExecutionPolicy RemoteSigned
3.png

参考文件:https://blog.csdn.net/dujyong/article/details/106359483

2、npm install 报错 cb.apply is not a function

解决:

  • win + r 打开运行,输入%appdata%
  • 删除 npm 和 npm-cache 文件夹
  • 执行npm cache clean --force命令

参考文件:https://blog.csdn.net/qq_37034928/article/details/108844381

3、npm install报错npm ERR! Maximum call stack size exceeded解决

给npm降级或者升级
比如:
  降级 : npm install -g npm@6.1.0
  升级 : npm install -g npm 升级到最新版
参考文件:https://www.bbsmax.com/A/mo5kgGkE5w/

4、Warning: Received true for a non-boolean attribute div.If you want to write it to the DOM, pass a string instead: div="true" or div={value.toString()}.
image.png

原因:


image.png
5、Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
原因:

我们不能在组件销毁后设置state,防止出现内存泄漏的情况。
关于react中切换路由时报以上错误,实际的原因是因为在组件挂载(mounted)之后进行了异步操作,比如ajax请求或者设置了定时器等,而你在callback中进行了setState操作。当你切换路由时,组件已经被卸载(unmounted)了,此时异步操作中callback还在执行,因此setState没有得到值。

解决:

在报错的组件里,加上:

componentWillUnmount = () => {
    this.setState = (state,callback)=>{
        return;
    };
}

参考文件:https://blog.csdn.net/u010565037/article/details/88716681

6、Warning: Expected ProcessSelect state to match memoized state before processing the update queue. This might either be because of a bug in React, or because a component reassigns its own this.state. Please file an issue.

报错原因:


image.png

解决:


image.png
7、Useless constructor no-useless-constructor

react中 Useless constructor no-useless-constructor报错
原因是构造函数里缺少state,下图是我的,报错,解决方法只要在constructor里面加上this.state={ },加上state对象就可以

constructor(props) {
    super(props);
    this.state = {
        value: []
    };
}
8、Support for the experimental syntax 'decorators-legacy' isn't currently enabled

1、npm run eject
2、在package.json文件下找到bebel属性,增加下面配置

"plugins": [
      [
        "@babel/plugin-proposal-decorators",
        {
          "legacy": true
        }
      ]
    ]

参考文件:https://blog.csdn.net/qq_41831345/article/details/101287368

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。