首页 > 其他分享 >dva使用yarn编译出错

dva使用yarn编译出错

时间:2024-04-15 10:26:40浏览次数:17  
标签:count app counter dva yarn state 出错 example

1. 报错信息

./src/models/example.jsModule build failed: TypeError: /Users/user/Desktop/learn-code/10.React/01_dva-came/src/models/example.js: path.isPrivate is not a function at Array.forEach ()
只要启动项目,然后修改example代码,只要example发生改变就会报该错误,无论是添加注释还是产生新的换行

2.原始代码

// example.js

import { routerRedux } from "dva/router";
// routerRedux == connected-react-redux
function delay(ms) {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve();
    }, ms);
  });
}

export default {
  namespace: "counter",
  state: {
    count: 1,
  },
  //ddd

  subscriptions: {
    setup({ dispatch, history }) {
      // eslint-disable-line
    },
  },

  effects: {
    *asyncAdd(action, { put, call }) {
      yield call(delay, 1000);

      yield put({ type: "counter/add" });
    },
    *goto({ payload }, { put }) {
      yield put(routerRedux.push(payload));
    },
  },

  reducers: {
    add(state, action) {
      console.log("state", state);

      return {
        count: state.count + 1,
      };
    },
  },
};

// index.js

import dva, { connect } from "dva";
import { Router, Route } from "dva/router";

import React from "react";
import "./index.css";
console.log("Router", Route);

// 1. Initialize
const app = dva();

// 2. Plugins
// app.use({});

// 3. Model
app.model(require("./models/example").default);

// 4. Router
// app.router(require("./router").default);
let Counter = connect((state) => state.counter)((props) => {
  let { count, dispatch } = props;
  console.log("count", props);

  return (
    <div>
      <p>{count}</p>
      <button
        onClick={() =>
          dispatch({
            type: "counter/add",
          })
        }
      >
        +
      </button>
      <button onClick={() => dispatch({ type: "counter/asyncAdd" })}>
        async +
      </button>
      <button onClick={() => dispatch({ type: "counter/goto", payload: "/" })}>
        goto /
      </button>
    </div>
  );
});
const Home = (props) => <div>home</div>;
app.router(({ history }) => (
  <Router history={history}>
    {/* Router 下面只能有一个元素  */}
    <React.Fragment>
      <Route path="/" exact component={Home} />
      <Route path="/counter" component={Counter} />
    </React.Fragment>
  </Router>
));

// 5. Start
app.start("#root");

3.最终查找原因

  • 并没有找到具体是因为什么,猜测原因是使用了yarn 重新安装依赖导致
  • 如果重新使用npm 安装依赖则恢复正常

++++++++++++++++++++++++++++++++++++++++++++++
经过测试发现,使用dva脚手架生成的项目如果后期使用了yarn安装依赖,就会导致出现该错误

标签:count,app,counter,dva,yarn,state,出错,example
From: https://www.cnblogs.com/coderzdz/p/18135268

相关文章

  • R_DVA
    Redefineddecisionvariableanalysismethodforlarge-scaleoptimizationanditsapplicationtofeatureselection作者贡献为了检测收敛变量之间的相互关系,提出了一种重新定义的低消耗DVA(R-DVA)。具体而言,R-DVA采用分层聚类方法,通过样本解与参考点之间的距离来衡量特征,......
  • npm,registry,镜像源,npm切换源,yarn,cnpm,taobao,nrs
    描述我们在使用node的npm下载依赖的时候,往往下载速度很慢,那是因为npm默认的是npm处于国外的官方镜像源。所以需要切换到国内的镜像源来加速依赖下载。所以本文推荐一款简单好用npm镜像源管理器,可以方便开发者管理自己的镜像源。推荐:npm-registry-nrs......
  • Qt程序加载Qt platform plugin 'xcb' 出错问题解决
    1.Qt程序运行环境ubuntu16.04Qt5.12.3Qt可执行程序编译后运行Qt可执行程序后出现报错报错内容:qt.qpa.plugin:CouldnotloadtheQtplatformplugin"xcb"in""eventhoughitwasfound.ThisapplicationfailedtostartbecausenoQtplatformplugincouldbe......
  • 52 Things: Number 13: Outline the use and advantages of projective point represe
    52Things:Number13:Outlinetheuseandadvantagesofprojectivepointrepresentation.52件事:第13件:概述投影点表示的用途和优点。 Thisisthelatestinaseriesofblogpoststoaddressthelistof '52ThingsEveryPhDStudentShouldKnow' todoCryptogr......
  • npm、yarn、pnpm设置镜像解决下载electron卡住的问题
    npm、yarn、pnpm设置镜像解决下载electron卡住的问题npmconfigsetELECTRON_MIRRORhttps://npmmirror.com/mirrors/electron/pnpmconfigsetELECTRON_MIRRORhttps://npmmirror.com/mirrors/electron/yarnconfigsetELECTRON_MIRRORhttps://npmmirror.com/mirrors/el......
  • yarn包管理器使用
    二、yarn包的使用1、yarn特点速度超快。Yarn缓存了每个下载过的包,所以再次使用时无需重复下载。同时利用并行下载以最大化资源利用率,因此安装速度更快。超级安全。在执行代码之前,Yarn会通过算法校验每个安装包的完整性。超级可靠。使用详细、简洁的锁文件......
  • Science Advances | 全球植物吸收的二氧化碳可能比我们想象的多20%
    在围绕气候变化及其对地球的深远影响的研究领域,几乎没有什么好消息可报告,然而一个国际科学家小组可能已经找到了一个值得庆祝的小胜利。西悉尼大学的于尔根-克瑙尔(JürgenKnauer)领导的科学家们利用现实的生态建模发现,全球植被实际吸收的人类排入大气中的二氧化碳可能会增加约2......
  • Hadoop集群下的wordcount运行出错类型及解决方法
    1、启动wordcont程序显示异常:原因:2、显示服务器连接不成功:原因:虚拟机配置问题,导致yarn服务没有启动3、运行结果不正确:原因:暂未发现,求解答......
  • npm 和 yarn 的使用区别
    从package.json中安装项目依赖:npminstall或yarn向package.json添加/安装新的项目依赖:npminstall{库名}--save或yarnadd{库名}向package.json添加/安装新的dev项目依赖(devDependency):npminstall{库名}--save-dev或yarnadd{库名}--dev删除依赖......
  • 03-template-advance
    03-TemplateAdvance源作者地址:https://github.com/bonfy/go-mega仅个人学习使用学习完第二章之后,你对模板已经有了基本的认识本章将讨论Go的组合特性,以及建立一个通用的调用模板的方法本章的GitHub链接为:Source,Diff,Zip匿名组合匿名组合其实是Go里的一个非常......