-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Crashed when using Webpack import()
#2463
Comments
Presumably some sort of cicular dependeny problem. https://github.com/fxxjdedd/vue-cli3-import-test/blob/master/src/common/index.js#L2-L3 let filename = 'import-test.js'
import(`@/pages/${filename}`)
I can't judge if this is inevitable or a bug in |
yeah, circular dependency is the point,but isn't it common in projects? |
Not really, circular dependencies should be avoided to prevent this kind of problem. Here for example, you can try to move your |
you are right, but there is another confusing thing,in the demo project,if we only import '@/common' in pageA, and delete import in pageB and pageC, it won't crash. |
Mmmmh, maybe because it's not "cyclic"? 🤔 But when pageA imports common that imports that all pages, all pages will import common that will import all pages... And that's a total mess 😅 |
Maybe it's indeed the https://github.com/vuejs/preload-webpack-plugin/blob/master/src/lib/extract-chunks.js#L43-L45 /cc @yyx990803 |
在使用vue-cli2 迁移到vue-cli3过程中. 我也遇到相同的问题. vue-cli2中index.html在根目录. vue-cli3 默认配置中,index.html在public中. 迁移过程中我尝试把index.html移动到public,项目没有任何问题能够启动. 但是我不移动index.html(保持和vue-cli2项目目录),通过配置vue.config.js 的pages选项定义HtmlWebpackPlugin的template. 项目在编译过程中就会无法编译通过:
整个项目我只有路由配置文件采用了import()语法. 我尝试删减路由配置测试是否是import()语法引起的问题. 在少于4个import()的情况下,项目是可以通过编译的. 4个及以上编译不通过. 但是如果不使用 vue.config.js中配置的pages.就完全没有这个问题.这让我很迷惑. |
Vue-cli3 is so charming🥞, but |
This is exploding on me in the same way in my Vue CLI 3 project with a multi-page build. It happens once certain dependencies are included. @LinusBorg it seems like this would be avoidable if the plugin kept track of what was processed in I haven't groked what the plugin does where it's crashing yet, but when searching around, I found https://github.com/webpack/webpack/blob/master/lib/optimize/EnsureChunkConditionsPlugin.js (potentially very unrelated), but noticed it was tracking chunk groups in a This might be logically wrong, but at least I was able to get my app running in dev mode temporarily by breaking the recursion by adding a
Seems like this should be addressable by somebody who knows what actually should happen here. Without a fix, is it impossible to have a multi-page build with circular references? |
Thanks for these valuable pointers, we will check this out as soon as we can. If you want rot make the multi page build work for now, you could remove this plugin, which is "only" responsible for turning "normal" script tags into "preload" ones, so the build should work with out it if memory serves. |
cannot delete preload plugin in vue.config.js, i'm so confused.
|
You are using the
... and each instance has its own name, as you can see in the output of inspect:
You will have to remove all of these. |
Very helpful advice! In case anybody is having trouble with this, here's the idea:
|
Thanks, it solve my same problem, |
@wuservices where did you get the |
He likely saved the |
I had similar problem that managed to workaround by moving the pages inside webpack config in the entry section like this:
|
I think @vue/preload-webpack-plugin should update to support the cicular dependency like: |
I have made a cli-service : ${projectDir}/build/vue-cli-service/remove-preload-prefetch.js module.exports = (api, projectOptions) => {
api.chainWebpack(webpackConfig => {
// see https://github.com/vuejs/vue-cli/issues/2463
if (projectOptions.pages) {
Object.keys(projectOptions.pages).forEach(page => {
webpackConfig.plugins.delete(`preload-${page}`)
webpackConfig.plugins.delete(`prefetch-${page}`)
})
}
})
} Then use it in package.json "vuePlugins": {
"service": [
"build/vue-cli-service/remove-preload-prefetch.js"
]
}, |
@viruscamp - I get this error on build TypeError: Cannot destructure property npm ERR! A complete log of this run can be found in: |
@luxueyan last time I checked it was in sync with the upstream package, so I believe that commit did not fully fixed the circular dependency issue, we need to investigate further. |
@wuservices Thank you so much! Your workaround saved me! Any expected plans to resolve this issue? |
@barakbd-bluevine I get the same error when using a custom vue-cli service plugin with node v12. But I don't think it is related to this issue here. |
Any update @LinusBorg on this issue? I've started experiencing it as well, but can't find the underlying cause of the circular dependency 😞 The proposed fix by @wuservices to extract-chunks.js works, however since you're modifying the source of Is there a better way to disable the preload-webpack-plugin? Or an update on when @vue/preload-webpack-plugin will be patched to resolve this issue? |
THB no, thia got drowned out a bit. If someone was up for PR what would be welcomed. |
@LinusBorg I sent @wuservices's suggested fix as PR here vuejs/preload-webpack-plugin#3. |
/cc @sodatea |
Fixed in @vue/preload-webpack-plugin v1.1.1 |
2. "pages" option leads to vuejs/vue-cli#2463. Upgrade vue related packages to fix it 3. fix autoprefixer warning https://github.com/postcss/autoprefixer/releases/tag/9.6.0 4. draft dapp Data point rewards screen
Version
3.0.1
Reproduction link
https://github.com/fxxjdedd/vue-cli3-import-test.git
Node and OS info
Node 10.3.0, yarn 1.9.4, Windows10
Steps to reproduce
yarn install && yarn serve
What is expected?
running
What is actually happening?
crashed with error:
概述:
这个问题是在我迁移项目到cli3时遇到的,项目中使用到了import(),并且它的参数是一个变量。
我总结了一下,出现这个问题的需要两个条件:
使用了Webpack的import()动态导入功能,且参数是一个变量(这个变量即使已经限制了文件夹范围,依然会有问题)。
包含上述行为的.js文件在多页面应用中被多个page同时引用(我实验了一下,发现至少需要3个page)。另外,更加奇怪的是,从非pages文件引入就没这个问题。
注意:
需要结合我给的reproduction项目看一下:
The text was updated successfully, but these errors were encountered: