Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

点击切换路由的时候,有时候会报错,Error: Loading chunk 1 failed. at HTMLScriptElement.d (bootstrap 7d5ba07478b35f182b62:103) #439

Open
maryrui opened this issue Jan 30, 2018 · 50 comments

Comments

Projects
None yet
@maryrui
Copy link

commented Jan 30, 2018

只有在 打包后的线上环境会出错,用的是addRouter 动态 添加的,万分感谢楼主指导,谢谢
Error: Loading chunk 1 failed.
at HTMLScriptElement.d (bootstrap 7d5ba07478b35f182b62:103)

@PanJiaChen

This comment has been minimized.

Copy link
Owner

commented Jan 31, 2018

请提供更详细信息

@maryrui

This comment has been minimized.

Copy link
Author

commented Jan 31, 2018

image
只有点击路由切换的时候会出现这种错,每次加载报错的区块都不一样(比如:Loading chunk 1 failed.||Loading chunk 2 failed.),前后台两个分开单独项目,都出现了这种问题,后台涉及权限用的是vuex 动态加载路由,前台没有使用。(所有的后端交互都是使用dispatch,会不会有影响)会不会是npm打包问题,毕竟npm经常出错

@maryrui

This comment has been minimized.

Copy link
Author

commented Jan 31, 2018

image
这是报错的源码区域

@maryrui

This comment has been minimized.

Copy link
Author

commented Jan 31, 2018

image
楼主自己的项目也会出现这种报错哦

@PanJiaChen

This comment has been minimized.

Copy link
Owner

commented Jan 31, 2018

并不能出现,你出现这个问题很多可能是缓存问题。
@maryrui 能稳定重现么?

@maryrui

This comment has been minimized.

Copy link
Author

commented Feb 1, 2018

image
重现度还有点高,点了十几次路由就重现

@PanJiaChen

This comment has been minimized.

Copy link
Owner

commented Feb 1, 2018

mac chrome 我试了很久都没能重现

@luchanan

This comment has been minimized.

Copy link

commented Feb 8, 2018

我也遇到这个问题,然后我去运行楼主的项目,发现在登录的时候出现这个问题的几率非常高

image

我只改了一处config/index.js中build的

assetsPublicPath: './'
改为
assetsPublicPath: '/test/',

打包之后,你在本地运行这个打包后项目,是没有这个问题的

但是把它放在服务器的话,重现几乎90%

网址只有一个域名,所以用test文件夹作为项目区分

@luchanan

This comment has been minimized.

Copy link

commented Feb 10, 2018

莫名奇妙域名被注入script(非本项目)脚本,导致出错,没有就是好的

@maryrui

This comment has been minimized.

Copy link
Author

commented Feb 24, 2018

@luchanan 那你解决了吗,动态加载路由确实会出现此问题,楼主的项目用mac的chrome确实不会出现此问题

@maryrui

This comment has been minimized.

Copy link
Author

commented Feb 24, 2018

image
window chrome重现的非常高,换了同事的机子重现度也一样

@luchanan

This comment has been minimized.

Copy link

commented Feb 24, 2018

@maryrui,你看看你项目head有没有被注入一些奇怪的script,自从没有那被注入的script我就没有重现了,你看看是不是这个导致的,我也是用w10+chrome

@seean-chan

This comment has been minimized.

Copy link

commented Mar 2, 2018

也出现了同样的问题,在打包后的线上环境会出错,点击侧栏卡顿,然后过很久就报错,压面页跳转不出来。有没有什么解决方法?
error

@guohui666

This comment has been minimized.

Copy link

commented May 24, 2018

也是一样的问题

@Yezily

This comment has been minimized.

Copy link

commented May 28, 2018

谢谢花裤衩大佬的指导,我也出现了同样的问题,不使用动态加载有一段时间没出现,现在又出现了,
我两个项目都出现了这个问题,都引入了楼主的模板里面的部分内容,目前还没着找到具体原因,
每次出现都是点击切换路由的时候,每次出现的时候点击的路由都不一样,刷新页面就好了,本地没有过,都是打包到服务器上才有的

这是使用动态挂载路由的时候报错内容

Mr.e._withTask.i._withTask @ vendor.218c81380028c4c91648.js:12
vendor.218c81380028c4c91648.js:6 Error: Loading chunk 14 failed.
at HTMLScriptElement.i (manifest.655bda8cfcc9f5f6b104.js:1)
s @ vendor.218c81380028c4c91648.js:6
(anonymous) @ vendor.218c81380028c4c91648.js:6
(anonymous) @ vendor.218c81380028c4c91648.js:6
(anonymous) @ vendor.218c81380028c4c91648.js:6
Promise rejected (async)
(anonymous) @ vendor.218c81380028c4c91648.js:6
(anonymous) @ vendor.218c81380028c4c91648.js:6
(anonymous) @ vendor.218c81380028c4c91648.js:6
mt @ vendor.218c81380028c4c91648.js:6
(anonymous) @ vendor.218c81380028c4c91648.js:6
d @ vendor.218c81380028c4c91648.js:6
r @ vendor.218c81380028c4c91648.js:6
r @ vendor.218c81380028c4c91648.js:6
(anonymous) @ vendor.218c81380028c4c91648.js:6
(anonymous) @ vendor.218c81380028c4c91648.js:6
(anonymous) @ app.31c99b36423b330e6a39.js:1
d @ vendor.218c81380028c4c91648.js:6
r @ vendor.218c81380028c4c91648.js:6
r @ vendor.218c81380028c4c91648.js:6
ht @ vendor.218c81380028c4c91648.js:6
_t.confirmTransition @ vendor.218c81380028c4c91648.js:6
_t.transitionTo @ vendor.218c81380028c4c91648.js:6
e.push @ vendor.218c81380028c4c91648.js:6
Pt.push @ vendor.218c81380028c4c91648.js:6
handleNav @ app.31c99b36423b330e6a39.js:1
click @ app.31c99b36423b330e6a39.js:1
e @ vendor.218c81380028c4c91648.js:12

这个是关掉动态挂载之后出现的报错

image

@TobyHong

This comment has been minimized.

Copy link

commented Jun 2, 2018

@TobyHong

This comment has been minimized.

Copy link

commented Jun 2, 2018

所以说现在没答案?

@TobyHong

This comment has been minimized.

Copy link

commented Jun 2, 2018

找到答案了,修改webpack.base里面的相关路径

@wangzz719

This comment has been minimized.

Copy link

commented Jun 3, 2018

@TobyHong 请问是如何解决的?

@wangzz719

This comment has been minimized.

Copy link

commented Jun 3, 2018

将 config.index.js 下的 assetsPublicPath 修改为:
assetsPublicPath: '/',
可以解决问题。

@Yezily

This comment has been minimized.

Copy link

commented Jun 4, 2018

@wangzz719 可是config.index.js 下面的assetsPublicPath 默认参数就是'/'
image

@TobyHong

This comment has been minimized.

Copy link

commented Jun 4, 2018

@Yezily 你改成./
还有下面引入elementUI有些项目也会出问题,这个也可以排查下。

@Yezily

This comment has been minimized.

Copy link

commented Jun 4, 2018

@TobyHong 好的 我去试试,谢了大兄弟

@qyf0310

This comment has been minimized.

Copy link

commented Jun 8, 2018

按将 @wangzz719 说的,把config.index.js 下的 assetsPublicPath 修改为:
assetsPublicPath: '/',
解决了

@ChasonHong

This comment has been minimized.

Copy link

commented Jun 12, 2018

@PanJiaChen 打包后放在服务器访问,间隔时间不等再操作,也会偶现Loading chunk 1 failed.||Loading chunk 0 failed,就是使用这个assetsPublicPath: '/',也是一样报错

@ADengrc

This comment has been minimized.

Copy link

commented Jun 14, 2018

qq 20180614180433
上传到线上后使用公司WIFI第一次访问该文件会被替换所以报错,当我使用4G网络访问却不会报错,应该是运营商网络劫持

@sebastianleecn

This comment has been minimized.

Copy link

commented Jul 21, 2018

router index.js 关闭 history(需要后端支持)

export default new Router({
// mode: 'history',
scrollBehavior: () => ({ y: 0 }),
routes: constantRouterMap
})

@IssueHuntBot

This comment has been minimized.

Copy link

commented Nov 29, 2018

@0maxxam0 has funded $80.00 to this issue. See it on IssueHunt

@xyzshen

This comment has been minimized.

Copy link

commented Jan 17, 2019

所以现在还没有解决

@TobyHong 好的 我去试试,谢了大兄弟

'./'这种方法可行吗?

@PanJiaChen

This comment has been minimized.

Copy link
Owner

commented Jan 17, 2019

话说你们能稳定重现么。。我最近特意加入了这个报错的监控
报错概率很低。

@xyzshen

This comment has been minimized.

Copy link

commented Jan 17, 2019

话说你们能稳定重现么。。我最近特意加入了这个报错的监控
报错概率很低。

话说 每天很多次

@PanJiaChen

This comment has been minimized.

Copy link
Owner

commented Jan 17, 2019

确定两个问题

  • 你们静态资源是 https的么?
  • 是个别js这样?还是所有异步加载的chunk js 都有问题?
@xyzshen

This comment has been minimized.

Copy link

commented Jan 18, 2019

怎么解决呢?

@PanJiaChen

This comment has been minimized.

Copy link
Owner

commented Jan 18, 2019

@xyzshen 你都没回答我的问题。。。

@xyzshen

This comment has been minimized.

Copy link

commented Jan 18, 2019

@PanJiaChen 1:http 2: 只是导航栏

@PanJiaChen

This comment has been minimized.

Copy link
Owner

commented Jan 18, 2019

什么叫只是导航栏

@xyzshen

This comment has been minimized.

Copy link

commented Jan 18, 2019

就是切换导航栏的时候报错;其它组建不报这个错误

@PanJiaChen

This comment has been minimized.

Copy link
Owner

commented Jan 18, 2019

本地执行 npm run build:prod --preview 之后能重现这个问题么?

@xyzshen

This comment has been minimized.

Copy link

commented Jan 18, 2019

@smile921

This comment has been minimized.

Copy link

commented Jan 21, 2019

也遇到这个问题了,可以肯定是打包的问题,因为统一的代码有时候打包就没问题,有时候有问题,只能重新打包,但是怎么解决还不知道根源

@ChobitsSP

This comment has been minimized.

Copy link

commented Mar 12, 2019

@gyxyl

This comment has been minimized.

Copy link

commented Mar 21, 2019

打包到测试环境之后出现这个问题,assetsPublicPath参数默认是/,后来想起自己不是用的npm源打包的,切换成npm源之后就好了

@Tingoo

This comment has been minimized.

Copy link

commented Mar 26, 2019

我们也遇到同样的问题,最后发现是运营商劫持(联通)

@mia330

This comment has been minimized.

Copy link

commented Apr 16, 2019

image
打开线上的报的,请问大家解决了吗?

@musi1024

This comment has been minimized.

Copy link

commented Apr 24, 2019

没有呢

@cxxly

This comment has been minimized.

Copy link

commented May 7, 2019

+1
image

@lzzhanglin

This comment has been minimized.

Copy link

commented May 9, 2019

ws改了assetsPublicPath 就默认的 不加点 就没问题了

@mia330

This comment has been minimized.

Copy link

commented May 13, 2019

@lzzhanglin 本来就没有点啊

@lzzhanglin

This comment has been minimized.

Copy link

commented May 13, 2019

@lzzhanglin 本来就没有点啊

那我就不清楚了 反正我是取消那个点就没有问题了

@17khba

This comment has been minimized.

Copy link

commented May 14, 2019

复现步骤loading * chunk failed

解决方案,未测试(参考链接里的回答):

// main.js
router.onError(err => {
  const pattern = /^Loading chunk (\d)+ failed\./;
  const isChunkLoadingFailed = pattern.test(err.message);

  if (isChunkLoadingFailed) {
    Message({
      type: 'error',
      message: '服务器版本已更新,正在刷新本地缓存,请稍后...',
      duration: 4000
    })

    window.location.replace(window.location.href);
  }

  console.log('出错了', err);
})

@PanJiaChen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.