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

Calm esm warnings #3872

Merged
merged 3 commits into from
Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/silent-trains-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

Don't show ESM warnings when consumed via dynamic import.
49 changes: 48 additions & 1 deletion integration/esm-only-warning-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@ test.beforeAll(async () => {
import b from "esm-only-exports";
import c from "esm-only-sub-exports";
import d from "esm-cjs-exports";
import e from "cjs-dynamic-import";

export function loader() {
export async function loader() {
let { default: f } = await import("esm-only-exports-b");
return json({
a: a(),
b: b(),
c: c(),
d: d(),
e: e(),
f: f(),
});
}

Expand Down Expand Up @@ -79,6 +83,40 @@ test.beforeAll(async () => {
"node_modules/esm-only-exports/index.js": js`
export default () => "esm-only-no-exports";
`,
"node_modules/esm-only-exports-b/package.json": json({
name: "esm-only-exports-b",
version: "1.0.0",
type: "module",
main: "index.js",
exports: {
".": "./index.js",
"./package.json": "./package.json",
},
}),
"node_modules/esm-only-exports-b/index.js": js`
export default () => "esm-only-no-exports-b";
`,
"node_modules/esm-only-exports-c/package.json": json({
name: "esm-only-exports-c",
version: "1.0.0",
type: "module",
main: "index.js",
exports: {
".": "./index.js",
"./package.json": "./package.json",
},
}),
"node_modules/esm-only-exports-c/index.js": js`
export default () => "esm-only-no-exports-c";
`,
"node_modules/cjs-dynamic-import/package.json": json({
name: "cjs-dynamic-import",
version: "1.0.0",
main: "index.js",
}),
"node_modules/cjs-dynamic-import/index.js": js`
module.exports = async () => "esm-only-no-exports-d" + (await import("esm-only-exports-c")).default();
`,
"node_modules/esm-only-sub-exports/package.json": json({
name: "esm-only-sub-exports",
version: "1.0.0",
Expand Down Expand Up @@ -143,6 +181,15 @@ test("logs warnings for ESM only packages", async () => {
expect(buildOutput).toContain(
"esm-only-exports is possibly an ESM only package"
);
expect(buildOutput).not.toContain(
"esm-only-exports-b is possibly an ESM only package"
);
expect(buildOutput).not.toContain(
"esm-only-exports-c is possibly an ESM only package"
);
expect(buildOutput).not.toContain(
"cjs-dynamic-import is possibly an ESM only package"
);
expect(buildOutput).toContain(
"esm-only-sub-exports is possibly an ESM only package"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function serverBareModulesPlugin(
return {
name: "server-bare-modules",
setup(build) {
build.onResolve({ filter: /.*/ }, ({ importer, path }) => {
build.onResolve({ filter: /.*/ }, ({ importer, kind, path }) => {
// If it's not a bare module ID, bundle it.
if (!isBareModuleId(resolvePath(path))) {
return undefined;
Expand Down Expand Up @@ -103,6 +103,7 @@ export function serverBareModulesPlugin(
if (
onWarning &&
!isNodeBuiltIn(packageName) &&
kind !== "dynamic-import" &&
(!remixConfig.serverBuildTarget ||
remixConfig.serverBuildTarget === "node-cjs")
) {
Expand Down