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

fix(dev): remove server bare import package check #7214

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 1 addition & 44 deletions packages/remix-dev/compiler/server/plugins/bareImports.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { isAbsolute, relative } from "node:path";
import { builtinModules } from "node:module";
import { isAbsolute } from "node:path";
import type { Plugin } from "esbuild";

import {
Expand All @@ -8,7 +7,6 @@ import {
} from "../virtualModules";
import { isCssSideEffectImportPath } from "../../plugins/cssSideEffectImports";
import { createMatchPath } from "../../utils/tsconfig";
import { detectPackageManager } from "../../../cli/detectPackageManager";
import type { Context } from "../../context";
import { getLoaderForFile } from "../../utils/loaders";

Expand Down Expand Up @@ -85,36 +83,6 @@ export function serverBareModulesPlugin(ctx: Context): Plugin {
return undefined;
}

let packageName = getNpmPackageName(path);
let pkgManager = detectPackageManager() ?? "npm";

// Warn if we can't find an import for a package.
if (
!isNodeBuiltIn(packageName) &&
!/\bnode_modules\b/.test(importer) &&
// Silence spurious warnings when using Yarn PnP. Yarn PnP doesn’t use
// a `node_modules` folder to keep its dependencies, so the above check
// will always fail.
(pkgManager === "npm" ||
(pkgManager === "yarn" && process.versions.pnp == null))
) {
try {
require.resolve(path, { paths: [importer] });
} catch (error: unknown) {
ctx.logger.warn(`could not resolve "${path}"`, {
details: [
`You imported "${path}" in ${relative(
process.cwd(),
importer
)},`,
"but that package is not in your `node_modules`.",
"Did you forget to install it?",
],
key: path,
});
}
}

if (ctx.config.serverDependenciesToBundle === "all") {
return undefined;
}
Expand All @@ -138,17 +106,6 @@ export function serverBareModulesPlugin(ctx: Context): Plugin {
};
}

function isNodeBuiltIn(packageName: string) {
return builtinModules.includes(packageName);
}

function getNpmPackageName(id: string): string {
let split = id.split("/");
let packageName = split[0];
if (packageName.startsWith("@")) packageName += `/${split[1]}`;
return packageName;
}

function isBareModuleId(id: string): boolean {
return !id.startsWith("node:") && !id.startsWith(".") && !isAbsolute(id);
}
Loading