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

Vitepress 引入 naive-ui build报错 #4166

Closed
sky124380729 opened this issue Dec 9, 2022 · 22 comments
Closed

Vitepress 引入 naive-ui build报错 #4166

sky124380729 opened this issue Dec 9, 2022 · 22 comments
Labels
feature request New feature or request

Comments

@sky124380729
Copy link

TuSimple/naive-ui version (版本)

2.34.2

Vue version (Vue 版本)

3.2.45

Browser and its version (浏览器及其版本)

chrome latest

System and its version (系统及其版本)

win19

Node version (Node 版本)

Reappearance link (重现链接)

vuejs/vitepress#1399

Reappearance steps (重现步骤)

  1. 使用vitepress构建项目
  2. 引入naive-ui
  3. 执行build打包

Expected results (期望的结果)

能够正常打包

Actual results (实际的结果)

打包报错

Remarks (补充说明)

vuejs/vitepress#1399

#vuejs/vitepress#1399

@github-actions github-actions bot added the untriaged need to sort label Dec 9, 2022
@jahnli
Copy link
Collaborator

jahnli commented Dec 10, 2022

docs/.vitepress/theme/index.js
尝试

import DefaultTheme from "vitepress/theme";
import { install } from "naive-ui";

export default {
  ...DefaultTheme,
  enhanceApp({ app }) {
    DefaultTheme.enhanceApp({ app });
    install(app);
  }
};

@sky124380729
Copy link
Author

docs/.vitepress/theme/index.js 尝试

import DefaultTheme from "vitepress/theme";
import { install } from "naive-ui";

export default {
  ...DefaultTheme,
  enhanceApp({ app }) {
    DefaultTheme.enhanceApp({ app });
    install(app);
  }
};

这样是可以的,但是就不能按需导入了吧

@jahnli
Copy link
Collaborator

jahnli commented Dec 12, 2022

好像是的,目前还找到按需引入的方案,如果有的话通知下

@sky124380729
Copy link
Author

好像是的,目前还找到按需引入的方案,如果有的话通知下

好的,目前已经能解决我的需求,非常感谢,后续找到方案会艾特你

@canyuegongzi
Copy link

有解决了吗?

@canyuegongzi
Copy link

好像是的,目前还找到按需引入的方案,如果有的话通知下

知道了, es 模式的产物文件必须要以mjs 为扩展

@sky124380729
Copy link
Author

好像是的,目前还找到按需引入的方案,如果有的话通知下

知道了, es 模式的产物文件必须要以mjs 为扩展

有找到合适的方案吗,全量导入build的时候也是不行的现在

@windsonR
Copy link

windsonR commented Jun 1, 2023

可以在vue文件中这样子用

const NDropdown = defineClientComponent(() => {
  return import('naive-ui/es/dropdown').then(d => d.NDropdown)
})

defineClientComponent包装一层.
vitepress文档

@canyuegongzi
Copy link

好像是的,目前还找到按需引入的方案,如果有的话通知下

知道了, es 模式的产物文件必须要以mjs 为扩展

有找到合适的方案吗,全量导入build的时候也是不行的现在

自己clone 一份源码重新构建一下,把构建产物的文件的后缀名修改下,或者修改喜爱node_modules中的文件后缀

@sky124380729
Copy link
Author

可以在vue文件中这样子用

const NDropdown = defineClientComponent(() => {
  return import('naive-ui/es/dropdown').then(d => d.NDropdown)
})

defineClientComponent包装一层. vitepress文档

这个应该是vitepress新特性,晚点我试一下

@meilZhu
Copy link

meilZhu commented Jun 26, 2023

You can do this:
Modify the dependency method you need to introduce to this:
import * as pkg from '....'
const { *** } = pkg

@sky124380729
Copy link
Author

sky124380729 commented Jun 26, 2023

You can do this: Modify the dependency method you need to introduce to this: import * as pkg from '....' const { *** } = pkg

have you tried? i tried this way last year, but it did not work as well...

@meilZhu
Copy link

meilZhu commented Jun 26, 2023

yes, i have tried

@edgexie
Copy link
Contributor

edgexie commented Nov 5, 2023

You can do this: Modify the dependency method you need to introduce to this: import * as pkg from '....' const { *** } = pkg

yes, it is. But not elegant enough

@lnzhangsong
Copy link

话说这么长时间了还没有解决吗?
现在有个临时方案就是 .vitepress/config.mts 文件中 添加如下代码

vite: {
    ssr: {
      noExternal: ["naive-ui"],
    },
  },

@edgexie
Copy link
Contributor

edgexie commented Feb 27, 2024

话说这么长时间了还没有解决吗?

现在有个临时方案就是 .vitepress/config.mts 文件中 添加如下代码

vite: {

    ssr: {

      noExternal: ["naive-ui"],

    },

  },

这样就让naiveui 不参与ssr了吧?我觉得这个问题是因为naiveui没有完全按照es模块的规范做。

@hyp530
Copy link

hyp530 commented Mar 3, 2024

话说这么长时间了还没有解决吗?
现在有个临时方案就是 .vitepress/config.mts 文件中 添加如下代码

vite: {

    ssr: {

      noExternal: ["naive-ui"],

    },

  },

这样就让naiveui 不参与ssr了吧?我觉得这个问题是因为naiveui没有完全按照es模块的规范做。

这个并不能彻底解决naiveui的引入问题。我用了,但像还是编译不出来:#5741

@lnzhangsong
Copy link

话说这么长时间了还没有解决吗?
现在有个临时方案就是 .vitepress/config.mts 文件中 添加如下代码

vite: {

    ssr: {

      noExternal: ["naive-ui"],

    },

  },

这样就让naiveui 不参与ssr了吧?我觉得这个问题是因为naiveui没有完全按照es模块的规范做。

这个并不能彻底解决naiveui的引入问题。我用了,但像还是编译不出来:#5741

我看了一下你的源码,我说的文件是 .vitepress/config.mts 而不是 .vitepress/vite 配置文件,此外官方文档中只有描述在 config.mts 中配置 vite,没有说在其他文件中做处理 文档地址

@jahnli
Copy link
Collaborator

jahnli commented Mar 8, 2024

https://github.com/becem-gharbi/nuxt-Naiveui 看看是否可以解决 SSR

@lnzhangsong
Copy link

话说这么长时间了还没有解决吗?
现在有个临时方案就是 .vitepress/config.mts 文件中 添加如下代码

vite: {

    ssr: {

      noExternal: ["naive-ui"],

    },

  },

这样就让naiveui 不参与ssr了吧?我觉得这个问题是因为naiveui没有完全按照es模块的规范做。

这个我看别人的描述是因为 生成的产物存在问题,不能参与 ssr,具体参考已解决 Vite SSR 生产构建报错

@jahnli
Copy link
Collaborator

jahnli commented Mar 12, 2024

This issue does not have any recent activity. If you are still experiencing similar problems, open a new error, including a minimal copy of the problem

@jahnli jahnli closed this as completed Mar 12, 2024
@07akioni
Copy link
Collaborator

07akioni commented May 6, 2024

https://www.naiveui.com/en-US/os-theme/docs/vitepress

@07akioni 07akioni added feature request New feature or request and removed untriaged need to sort labels May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

9 participants