Skip to content

Dep optimization failed with vite2.0 #3481

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

Closed
1 task done
Hawods opened this issue Jan 4, 2021 · 8 comments
Closed
1 task done

Dep optimization failed with vite2.0 #3481

Hawods opened this issue Jan 4, 2021 · 8 comments
Labels

Comments

@Hawods
Copy link

Hawods commented Jan 4, 2021

  • I have searched the issues of this repository and believe that this is not a duplicate.

Version

2.0.0-rc.7

Environment

vue: 3.0.5, vite: 2.0.0-beta.4

Reproduction link

https://github.com/Hawods/antd-vite2-test

Steps to reproduce

  1. cd antd-vite2-test
  2. npm install (or yarn)
  3. npm run dev (or yarn dev)

What is expected?

Dev server started

What is actually happening?

Dep optimization failed with error:
[vite]: Rollup failed to resolve import "indexof" from "indexof?commonjs-external".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
build.rollupOptions.external

@B1anker
Copy link

B1anker commented Jan 5, 2021

// vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [vue()],
  optimizeDeps: {
    exclude: ['ant-design-vue', 'lodash']
  }
})

@bhabgs
Copy link

bhabgs commented Jan 5, 2021

// vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [vue()],
  optimizeDeps: {
    exclude: ['ant-design-vue', 'lodash']
  }
})

这并不能解决任何问题

@bhabgs
Copy link

bhabgs commented Jan 5, 2021

I think

This issue should be referred to the Vite team。

link

@yyx990803
Copy link

vitejs/vite#1360 (comment)

Ant Design Vue 有几个很有问题的依赖,建议仔细捋一遍依赖,尽量不要再依赖 CommonJS 格式的。

@ghost
Copy link

ghost commented Jan 5, 2021

@tangjinzhou 按照尤大的建议,我捋了一遍,看看能不能帮到。如果还没人来解决,我可以解决一部分。但是很多还是要你们来处理。

整理如下

可以移动到devDependencies的包有

  • @babel/runtime.
  • babel-helper-vue-jsx-merge-props
  • node-emoji

没用到的依赖有

  • add-dom-event-listener
  • intersperse
  • ismobilejs
  • is-negative-zero

一些建议的包

  • omit.js 这个包可以用 lodash-es的omit代替
  • shallow-equal和shallowequal这两个包是否有重复
  • warning 这个包是否可以直接使用log代替

引用了 commonjs的包

  • component-classes 内部 require('indexof') 和require('component-indexof')
  • dom-closest 内部引用了require('dom-matches')
  • json2mq 内部引用了require('string-convert/camel2hyphen')
  • raf内部引用了require('performance-now')

@tangdw
Copy link

tangdw commented Apr 14, 2021

@tangjinzhou 按照尤大的建议,我捋了一遍,看看能不能帮到。如果还没人来解决,我可以解决一部分。但是很多还是要你们来处理。

整理如下

可以移动到devDependencies的包有

  • @babel/runtime.
  • babel-helper-vue-jsx-merge-props
  • node-emoji

没用到的依赖有

  • add-dom-event-listener
  • intersperse
  • ismobilejs
  • is-negative-zero

一些建议的包

  • omit.js 这个包可以用 lodash-es的omit代替
  • shallow-equal和shallowequal这两个包是否有重复
  • warning 这个包是否可以直接使用log代替

引用了 commonjs的包

  • component-classes 内部 require('indexof') 和require('component-indexof')
  • dom-closest 内部引用了require('dom-matches')
  • json2mq 内部引用了require('string-convert/camel2hyphen')
  • raf内部引用了require('performance-now')

@chad-bin 大佬,你好。 我用 antd-mobile 里也有 component-classes 内部 require('indexof') 和require('component-indexof') 这个,导致打包后的文件里有 import 'indexof' 从而访问报错,请问有什么办法解决呢?
image

@byoungd
Copy link

byoungd commented Feb 20, 2022

这个问题有任何进展吗?

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants