No known conditions for “.“ entry in “vite-aliases“ package解决

最近在学付金权老师的vite课,讲的颇为不错,可惜我现在不找工作,所以没法买面试题支持他咯,学到vite插件的vitealiases时,按照视频里的代码写了一下,yarn dev后,发现报如下错误。
我的vite.base.config.js(类似于vite.config.js,只是多写了基本配置和扩展配置,看过视频的都懂)

import {defineConfig} from "vite"
//import { ViteAliases } from "vite-aliases";
import { ViteAliases } from 'vite-aliases';
//const postcssPresetEnv =require("postcss-preset-env")
export default defineConfig({
    optimizeDeps:{
        exclude:[],
    },
    envPrefix:"ENV_",//配置vite注入客户端环境变量
    css:{//对css的行为进行配置
        //modules配置最终会丢给postcss module
        modules:{
            localsConvention:"camelCase",
            scopeBehaviour:"local",
            //generateScopedName:"[name]_[local]_[hash:5]",
            /*generateScopedName:(name,filename,css)=>{
                console.log("name",name,"filename",filename,"css",css);
                return `${name}_${Math.random().toString(36).substr(3,8)}`;
            },*/
            hashPrefix:"hello",
            globalModulePaths:["./componentB.module.css"],//代表不想参与css模块化编码的模块。
        },
        preprocessorOptions:{//key+config key代表预处理器的名
            less:{//整个的配置对象都会最终给到
                math:"always",
                globalVars:{
                    mainColor:"red",
                }
            }, 
        },
        devSourcemap:true,
        /*postcss:{
            //plugins:[postcssPresetEnv()]
        }*/
    },
    build:{
        rollupOptions:{
            output:{
                assetFileNames:"[hash].[name].[ext]"
            }
        },
        assetsInlineLimit:4096,
        //outDir:"testDist"
        assetsDir:"static"
    },
    plugins:[
        ViteAliases()
    ],
})

报错信息:
$ vite
X [ERROR] [plugin externalize-deps] Failed to resolve entry for package “vite-aliases”. The package may have incorrect main/module/exports specified in its package.json: No
known conditions for “.” entry in “vite-aliases” package

node_modules/esbuild/lib/main.js:1327:27:
  1327 │         let result = await callback({
       ╵                            ^

at packageEntryFailure (file:///C:/Users/Administrator/Desktop/testvite/node_modules/vite/dist/node/chunks/dep-51c4f80a.js:34096:11)
at resolvePackageEntry (file:///C:/Users/Administrator/Desktop/testvite/node_modules/vite/dist/node/chunks/dep-51c4f80a.js:34091:9)
at tryNodeResolve (file:///C:/Users/Administrator/Desktop/testvite/node_modules/vite/dist/node/chunks/dep-51c4f80a.js:33834:20)
at file:///C:/Users/Administrator/Desktop/testvite/node_modules/vite/dist/node/chunks/dep-51c4f80a.js:62782:40
at requestCallbacks.on-resolve (C:\Users\Administrator\Desktop\testvite\node_modules\esbuild\lib\main.js:1327:28)
at handleRequest (C:\Users\Administrator\Desktop\testvite\node_modules\esbuild\lib\main.js:697:19)
at handleIncomingPacket (C:\Users\Administrator\Desktop\testvite\node_modules\esbuild\lib\main.js:719:7)
at Socket.readFromStdout (C:\Users\Administrator\Desktop\testvite\node_modules\esbuild\lib\main.js:647:7)
at Socket.emit (node:events:527:28)
at addChunk (node:internal/streams/readable:315:12)

This error came from the “onResolve” callback registered here:

node_modules/esbuild/lib/main.js:1251:20:
  1251 │       let promise = setup({
       ╵                     ^

at setup (file:///C:/Users/Administrator/Desktop/testvite/node_modules/vite/dist/node/chunks/dep-51c4f80a.js:62772:27)
at handlePlugins (C:\Users\Administrator\Desktop\testvite\node_modules\esbuild\lib\main.js:1251:21)
at buildOrServeImpl (C:\Users\Administrator\Desktop\testvite\node_modules\esbuild\lib\main.js:942:5)
at Object.buildOrServe (C:\Users\Administrator\Desktop\testv

搞了半天搞不懂,拿去问我哥了,他帮我看了下,
把import { ViteAliases } from ‘vite-aliases’;改成
import { ViteAliases } from ‘./node_modules/vite-aliases’;就可以了,可能是vite和webpack搜索模块的差异导致的吧,以后遇到问题再说,现在先不钻牛角尖,遇到问题再肝源码。

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

returnadsss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值