sorrycc / roadhog

🐷 Cli tool for creating react apps, configurable version of create-react-app.
2.72k stars 341 forks source link

从1.3.x 升级至 2.x的问题 #640

Open cpu220 opened 6 years ago

cpu220 commented 6 years ago

Environment(required) | 环境(必填)

dva 0.7.9

What happen?(发生了何种非正常现象)

按照升级文档进行操作。当进行到

如果有 babel-runtime 依赖和配置了 babel-plugin-transform-runtime 插件,需删除,因为已内置处理,否则可能会报 this.setDynamic is not a function 的错误 上述步骤的时候。

  1. 首先,删除哪个?
  2. 做以下尝试 babel-runtime && babel-plugin-transform-runtime 均升级到最新
    1. 2个不删则报错 this.setDynamic is not a function
    2. 删 babel-runtime 报错 this.setDynamic is not a function
    3. babel-plugin-transform-runtime 报错

      Module build failed: Error: Cannot find module 'babel-plugin-transform-runtime' from '/3_Code/work/test/dev'

      • Did you mean "@babel/transform-runtime"? at Array.map ()
        1. 2者都删,同3一样报错。
codering commented 6 years ago

问问题应该贴出你的关键信息,比如你的配置,你的package.json

cpu220 commented 6 years ago

.webpackrc

{
  "entry": "src/index.js", 
  "theme":{  
    "primary-color":"#3187F6",
    "border-radius-base": "2px",
    "font-size-base":"12px"
  },
  "env": {
    "development": {
      "extraBabelPlugins": [
        "dva-hmr",
        "transform-runtime",

        ["import", {
          "libraryName": "antd",
          "style": true
        }]
      ]
    },
    "production": {
      "extraBabelPlugins": [
        "transform-runtime",

        ["import", {
          "libraryName": "antd",
          "style": true
        }]
      ]
    }
  }
}

package.json

{
  "version": "1.0.10",
  "private": true,
  "scripts": {
    "start": "roadhog server",
    "build": "roadhog dev"
  },
  "dependencies": {
    "antd": "~3.2.3",
    "babel-runtime": "~6.9.2",
    "detect-browser": "~1.10.0",
    "dva": "~2.1.0",
    "dva-loading": "~0.2.0",
    "es6-promise": "~4.2.2",
    "localStorage": "~1.0.3",
    "moment": "~2.18.1",
    "qrcode.react": "~0.7.1",
    "rc-color-picker": "~1.2.3",
    "react": "~16.2.0",
    "react-dom": "~16.2.0",
    "react-router": "~4.2.0"
  },
  "devDependencies": {
    "babel-plugin-import": "~1.2.1",
    "babel-eslint": "~7.1.1",
    "babel-plugin-dva-hmr": "~0.4.1",
    "eslint": "~3.12.2",
    "eslint-config-airbnb": "~13.0.0",
    "eslint-plugin-import": "~2.2.0",
    "eslint-plugin-jsx-a11y": "~2.2.3",
    "eslint-plugin-react": "~6.8.0",
    "expect": "~1.20.2",
    "husky": "~0.12.0",
    "redbox-react": "~1.3.2",
    "roadhog": "~2.2.0",
    "react-router": "~4.1.1",
    "whatwg-fetch": "~2.0.3"
  }
}
codering commented 6 years ago

删除.webpackrc中的 所有"transform-runtime"试试呢?

cpu220 commented 6 years ago

经过了各种实验发现, 首先,删了并没有用 其次,从1.3.x 升到2.x ,改的文件不仅仅是那么几个。整个package里,尤其是eslint,版本与其配置文件的改动特别隐晦。

codering commented 6 years ago

我看Antd pro 也是用的这个,并没有什么问题

cpu220 commented 6 years ago
  1. 不仅仅是eslint的问题,你们文件对比下就知道了。估计我的版本比较早,改动文件是在太多。

  2. 发现个新的问题,如果以下错误,那么control+c 无法关闭node进程。于是再次npm start的时候,就会提示发现端口占用的提示。进程内会多创建一个node进程

    Module not found: Can't resolve 'xxx' in 'xxx/xxx'

  3. 我已经直接用 antD pro的 配置文件进行覆盖。启动各种报错

    'xxxx/xxx' does not contain an export named 'xxx'

    
    ApiUtil.js

export default { getJSON, postJSON }

A.js import { getJSON, postJSON } from '../ApiUtil';

// 报错 '../ApiUtil' does not contain an export named 'getJSON'. '../ApiUtil' does not contain an export named 'postJSON'.

 搜了下issues,发现有人提出解决方案,但并未成功。操作如下

  ``` javascript
ApiUtil.js

export default {
 getJSON, postJSON
}

../B/A.js
import ApiUtil from './ApiUtil';
const { getJSON, postJSON } = ApiUtil;

// 报错
Module not found: Can't resolve '../ApiUtil' in '../B/A'

于是进行以下尝试

ApiUtil.js

export default {
 getJSON, postJSON
}

../B/A.js
第一步
import ApiUtil from './ApiUtil'
const { getJSON, postJSON } = ApiUtil;
 第二步
const a = require('../a.js');
改成
const a = require('../a.js').defult;

最终,终于看到页面正常出现,且chrome没有任何报错。。。 整个升级过程几乎是开了3个工程,分别对比文件,然后不停的debug。最终,关于node进程无法正常关闭的问题,还是没解决

vipcxj commented 6 years ago

babel-runtime依赖需删除是因为最新的babel版本,依赖的名称基本改了,babel-XXX基本都变为@babel/XXX, babel-plugin-transform-runtime应该是指babel插件,这是全称,简写的话就是transform-runtime。事实上这个插件在新版本中也改名了,同样改成@babel/plugin-transform-runtime,简写为@babel/transform-runtime,其中@babel不能省略,因为省了就是两个完全不同插件。最后这俩东西roadhog2.0中应该都包含了,事实上roadhog2.0直接使用了一个preset,里面包括了这些东西,你不需要额外定义

tudou330121 commented 6 years ago

我也遇到了同样的问题 你解决了吗

cpu220 commented 6 years ago

经过一系列难以描述的修改后,跑是跑起来了,但实际上并不怎么好用。

naivehhr commented 5 years ago

一堆问题