Cantresolve@babelruntimehelpersesmextends的解决
同事检出我的项⽬,在 roadhog build 编译时,出现问题:
Module not found: Error: Can't resolve '@babel/runtime/helpers/esm/extends' in '/Users/everlose/workspace/scnode/msgcenter-sms/node_modules/history/esm'
根据下⾯的 ls 命令,我们能看到 history ⽬录的确不存在与项⽬跟路径,'/Users/everlose/workspace/scnode/msgcenter-
sms/node_modules/history/esm'。
$ npm ls history
msgcenter-sms@1.7.10 /Users/everlose/workspace/scnode/msgcenter-sms
├─┬ dva@2.4.1
│├── history@4.6.3  deduped
│├─┬ react-router-dom@4.3.1
││├── history@4.9.0
││└─┬ react-router@4.3.1
││└── history@4.9.0react router6
│└─┬ react-router-redux@5.0.0-alpha.9
│└── history@4.9.0
到 github 上的 history 模块代码,翻到 4.9.0 发现它所依赖 babel 的版本的确变为了 7,⽽项⽬主 babel 版本还是6。猜测可能是 babel 主版本的影响。
查看其 4.7.2 及之前还是使⽤ babel 6 的。故⽽解决⽅法就是
$ npm install history@4.7.2 --save
$ rm -rf node_modules
$ npm install
$ npm ls history
msgcenter-sms@1.7.10 /Users/everlose/workspace/scnode/msgcenter-sms
├─┬ dva@2.4.1
│├── history@4.7.2  deduped
│├─┬ react-router-dom@4.3.1
││├── history@4.7.2  deduped
││└─┬ react-router@4.3.1
││└── history@4.7.2  deduped
│└─┬ react-router-redux@5.0.0-alpha.9
│└── history@4.7.2  deduped
└── history@4.7.2
再编译时正常
$ npm run build
> msgcenter-sms@1.7.10 build /Users/everlose/workspace/scnode/msgcenter-sms
> roadhog build
Build completed in 33.632s
Compiled successfully.
File sizes after gzip:
681.58 KB  public/index.657ff4cf.js
37.33 KB  public/index.424c8126.css
⼼得
像这样⼤的更新,依赖版本整个换了,那个 history 依赖包不应该只是升级中间版本的。这些依赖包简直和⽆限套娃⼀样,我都不知道什么时候⽤到了,真的是坑⼈。