File tree Expand file tree Collapse file tree 2 files changed +21
-7
lines changed
packages/vite-plugin-cloudflare/src/plugins Expand file tree Collapse file tree 2 files changed +21
-7
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @cloudflare/vite-plugin " : patch
3+ ---
4+
5+ allow resolving unenv aliases to packages
Original file line number Diff line number Diff line change @@ -403,15 +403,24 @@ export class NodeJsCompat {
403403 ) : { unresolved : string ; resolved : string } | undefined {
404404 const alias = this . #env. alias [ source ] ;
405405
406- // These aliases must be resolved from the context of this plugin since the alias will refer to one of the
407- // `@cloudflare/unenv-preset` or the `unenv` packages, which are direct dependencies of this package,
408- // and not the user's project.
409406 // We exclude `externals` as these should be externalized rather than optimized.
410407 if ( alias && ! this . externals . has ( alias ) ) {
411- return {
412- unresolved : alias ,
413- resolved : resolvePathSync ( alias , { url : import . meta. url } ) ,
414- } ;
408+ try {
409+ // These aliases must be resolved from the context of this plugin since the alias can refer to one of
410+ // the `@cloudflare/unenv-preset` or the `unenv` packages, which are direct dependencies of this package,
411+ // and not the user's project.
412+ // When the alias is a package (i.e. the `debug` npm package), `resolvePathSync` will throw
413+ return {
414+ unresolved : alias ,
415+ resolved : resolvePathSync ( alias , { url : import . meta. url } ) ,
416+ } ;
417+ } catch {
418+ // Returns the raw alias when it can not be resolved.
419+ return {
420+ unresolved : source ,
421+ resolved : alias ,
422+ } ;
423+ }
415424 }
416425
417426 if ( this . entries . has ( source ) ) {
You can’t perform that action at this time.
0 commit comments