Skip to content

Commit 8fd4870

Browse files
committed
Cannot import "exports": { "module": ... } configured packages, instead we could get an error: Cannot use import statement outside a module
Reproduction of remix-run#9070
1 parent 8f6e21f commit 8fd4870

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

integration/bug-report-test.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,37 @@ test.beforeAll(async () => {
5959
////////////////////////////////////////////////////////////////////////////
6060
files: {
6161
"app/routes/_index.tsx": js`
62-
import { json } from "@remix-run/node";
63-
import { useLoaderData, Link } from "@remix-run/react";
64-
65-
export function loader() {
66-
return json("pizza");
67-
}
62+
import { myModule } from "my-module";
6863
6964
export default function Index() {
70-
let data = useLoaderData();
7165
return (
7266
<div>
73-
{data}
74-
<Link to="/burgers">Other Route</Link>
67+
{myModule}
7568
</div>
7669
)
7770
}
7871
`,
7972

80-
"app/routes/burgers.tsx": js`
81-
export default function Index() {
82-
return <div>cheeseburger</div>;
73+
// NOTE: If "type": "module", is added, this test passes
74+
"node_modules/my-module/package.json": `
75+
{
76+
"name": "my-module",
77+
"version": "1.0.0",
78+
"main": "main.js",
79+
"exports": {
80+
".": {
81+
"require": "./main.js",
82+
"import": "./main.esm.js"
83+
}
84+
}
8385
}
8486
`,
87+
"node_modules/my-module/main.esm.js": js`
88+
export const myModule = "hello from esm";
89+
`,
90+
"node_modules/my-module/main.js": js`
91+
exports.myModule = "hello from cjs";
92+
`,
8593
},
8694
});
8795

@@ -98,16 +106,16 @@ test.afterAll(() => {
98106
// add a good description for what you expect Remix to do 👇🏽
99107
////////////////////////////////////////////////////////////////////////////////
100108

101-
test("[description of what you expect it to do]", async ({ page }) => {
109+
test("Can be built and works", async ({ page }) => {
102110
let app = new PlaywrightFixture(appFixture, page);
103111
// You can test any request your app might get using `fixture`.
104112
let response = await fixture.requestDocument("/");
105-
expect(await response.text()).toMatch("pizza");
113+
expect(await response.text()).toMatch("hello from esm");
106114

107115
// If you need to test interactivity use the `app`
108116
await app.goto("/");
109-
await app.clickLink("/burgers");
110-
await page.waitForSelector("text=cheeseburger");
117+
// await app.clickLink("/burgers");
118+
// await page.waitForSelector("text=cheeseburger");
111119

112120
// If you're not sure what's going on, you can "poke" the app, it'll
113121
// automatically open up in your browser for 20 seconds, so be quick!

0 commit comments

Comments
 (0)