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

Optimized dependency error #1339

Closed
anncwb opened this issue Jan 4, 2021 · 7 comments
Closed

Optimized dependency error #1339

anncwb opened this issue Jan 4, 2021 · 7 comments

Comments

@anncwb
Copy link
Contributor

anncwb commented Jan 4, 2021

Do NOT ignore this template or your issue will have a very high chance to be closed without comment.

Describe the bug

When I added ant-design-vue, an error occurred.

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
`rollupInputOptions.external`
(node:28953) UnhandledPromiseRejectionWarning: 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
`rollupInputOptions.external`

I tried adding indexof to rollupInputOptions.external, but this did not work.

At the same time, the project has another error.

import Ant from 'ant-design-vue';

import 'ant-design-vue/dist/antd.css'

When the following two sentences are introduced at the same time, vite will prompt to add ant-design-vue/dist/antd.css to optimizeDeps.include. But after I added it, an error was reported, and the error message is as follows

Dep optimization failed with error:
Entry module cannot be external (node_modules/ant-design-vue/dist/antd.css).

Reproduction

  1. clone https://github.com/anncwb/vite-bug
  2. yarn serve

System Info

  • required vite version:
  • required Operating System:
  • required Node version:
  • Optional:
    • npm/yarn version
    • Installed vue version (from yarn.lock or package-lock.json)
    • Installed @vue/compiler-sfc version

Logs (Optional if provided reproduction)

  1. Run vite or vite build with the --debug flag.
  2. Provide the error log here.
@anncwb
Copy link
Contributor Author

anncwb commented Jan 4, 2021

This can be used normally in vite1.0

@Ttou
Copy link

Ttou commented Jan 4, 2021

@yyx990803 60a4708 好像只是把报错改成了报警,真正导致错误的原因似乎是 ant-design-vue 引用了 indexof 而 rollup 处理失败了
iShot2021-01-04 17 40 49

@qq31311137
Copy link

怎么解决,更新了 vite2 antd-vue 就报错了

@Ttou
Copy link

Ttou commented Jan 7, 2021

@qq31311137 看 antd 的 commit 记录好像解决了,等发版吧

@qq31311137
Copy link

@Ttou 看到了 谢谢

@evanwills
Copy link

Hi @anncwb

I just ran into this problem too. I fixed it (surprisingly) by adding a leading slash to the file path.

e.g. change import 'ant-design-vue/dist/antd.css' to

import '/ant-design-vue/dist/antd.css'

Hopefully, it will help you.

@cdll
Copy link

cdll commented Apr 14, 2021

Hi @anncwb

I just ran into this problem too. I fixed it (surprisingly) by adding a leading slash to the file path.

e.g. change import 'ant-design-vue/dist/antd.css' to

import '/ant-design-vue/dist/antd.css'

Hopefully, it will help you.

not helping, but thanks all the same~ 🙏

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants