Skip to content

Commit

Permalink
fix: don't try to resolve internal node modules via package.json svel…
Browse files Browse the repository at this point in the history
…te field (#266)

* fix: don't try to resolve internal node modules via package.json svelte field

* chore: merge imports
  • Loading branch information
dominikg committed Feb 4, 2022
1 parent 5786dab commit ed8a19c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-trees-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/vite-plugin-svelte': patch
---

don't try to resolve node internal modules via package.json svelte field
13 changes: 11 additions & 2 deletions packages/vite-plugin-svelte/src/utils/resolve.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import { createRequire } from 'module';
import { builtinModules, createRequire } from 'module';
import { is_common_without_svelte_field, resolveDependencyData } from './dependencies';
import { VitePluginSvelteCache } from './vite-plugin-svelte-cache';

Expand All @@ -8,7 +8,12 @@ export function resolveViaPackageJsonSvelte(
importer: string | undefined,
cache: VitePluginSvelteCache
): string | void {
if (importer && isBareImport(importee) && !is_common_without_svelte_field(importee)) {
if (
importer &&
isBareImport(importee) &&
!isNodeInternal(importee) &&
!is_common_without_svelte_field(importee)
) {
const cached = cache.getResolvedSvelteField(importee, importer);
if (cached) {
return cached;
Expand All @@ -28,6 +33,10 @@ export function resolveViaPackageJsonSvelte(
}
}

function isNodeInternal(importee: string) {
return importee.startsWith('node:') || builtinModules.includes(importee);
}

function isBareImport(importee: string): boolean {
if (
!importee ||
Expand Down

0 comments on commit ed8a19c

Please sign in to comment.