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

Cannot find module '/Users/zhangyanlong/WorkSpace/BAILI/vite-project/node_modules/vant/lib/ssr.js' #53

Closed
baily90 opened this issue Dec 1, 2021 · 4 comments

Comments

@baily90
Copy link

baily90 commented Dec 1, 2021

刚使用vite结合vant起了个项目,按照官方文档按需加载启动项目报错,请教大佬是什么原因

安装版本:
vite-plugin-style-import "1.4.0"
vite "2.6.14"

// vite.config.js配置 

import vue from '@vitejs/plugin-vue'
import styleImport from "vite-plugin-style-import";
export default {
  plugins: [
    vue(),
    styleImport({
      libs: [
        {
          libraryName: "vant",
          esModule: true,
          resolveStyle: (name) => `vant/es/${name}/style`,
        },
      ],
    }),
  ]
}
// 引入方式

<script setup lang="ts">
import { Button } from 'vant';
</script>

<template>
  <Button type="primary">主要按钮</Button>
</template>

报错信息如下:

上午10:45:23 [vite] Internal server error: Cannot find module '/Users/zhangyanlong/WorkSpace/BAILI/vite-project/node_modules/vant/lib/ssr.js'
  Plugin: vite:style-import
  File: /Users/zhangyanlong/WorkSpace/BAILI/vite-project/src/components/HelloWorld.vue
      at createEsmNotFoundErr (internal/modules/cjs/loader.js:912:15)
      at finalizeEsmResolution (internal/modules/cjs/loader.js:905:15)
      at resolveExports (internal/modules/cjs/loader.js:437:14)
      at Function.Module._findPath (internal/modules/cjs/loader.js:477:31)
      at Function.Module._resolveFilename (internal/modules/cjs/loader.js:872:27)
      at Function.resolve (internal/modules/cjs/helpers.js:94:19)
      at resolveNodeModules (/Users/zhangyanlong/WorkSpace/BAILI/vite-project/node_modules/vite-plugin-style-import/dist/index.js:49:61)
      at transformComponentCss (/Users/zhangyanlong/WorkSpace/BAILI/vite-project/node_modules/vite-plugin-style-import/dist/index.js:293:21)
      at TransformContext.transform (/Users/zhangyanlong/WorkSpace/BAILI/vite-project/node_modules/vite-plugin-style-import/dist/index.js:190:40)
      at processTicksAndRejections (internal/process/task_queues.js:95:5)
@yanstars
Copy link

yanstars commented Dec 1, 2021

貌似是因为 vant 支持了 nuxt使用 修改了 package导出文件 我 vant降级到3.3.2都行

@520ph
Copy link

520ph commented Dec 1, 2021

@chenjiahan lib/ssr.js 不存在

@baily90 baily90 closed this as completed Dec 1, 2021
@baily90 baily90 reopened this Dec 1, 2021
@baily90
Copy link
Author

baily90 commented Dec 1, 2021

按照楼上的方法可以正常使用,但是具体原因未知
1:vant版本选择3.3.2
2:配置文件中resolveStyle路径前面要加/node_modules,如下:

import vue from '@vitejs/plugin-vue'
import styleImport from "vite-plugin-style-import";
export default {
  plugins: [
    vue(),
    styleImport({
      libs: [
        {
          libraryName: "vant",
          esModule: true,
          // vant官方写法 `vant/es/${name}/style`
          resolveStyle: (name) => `/node_modules/vant/es/${name}/style`,  
        },
      ],
    }),
  ]
}

感谢提供解决方案,谢谢,此处结项

@baily90 baily90 closed this as completed Dec 1, 2021
@chenjiahan
Copy link

ssr.js 不存在的问题已经在 vant 3.3.4 版本修复

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants