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

这篇具有很好参考价值的文章主要介绍了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搜索模块的差异导致的吧,以后遇到问题再说,现在先不钻牛角尖,遇到问题再肝源码。文章来源地址https://www.toymoban.com/news/detail-600337.html

到了这里,关于No known conditions for “.“ entry in “vite-aliases“ package解决的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包