Skip to content

Commit

Permalink
Merge branch 'dev' into fix-vite-no-watch-build-viteChildCompiler
Browse files Browse the repository at this point in the history
  • Loading branch information
markdalgleish authored Dec 21, 2023
2 parents f85c6e2 + 3593c35 commit 3687e94
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/angry-poets-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/serve": patch
---

Use node `fileURLToPath` to convert source map URL to path
21 changes: 7 additions & 14 deletions .changeset/breezy-grapes-roll.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
---
"@remix-run/dev": minor
"@remix-run/dev": patch
---

Vite: Error messages when .server files are referenced by client
Vite: Error messages when `.server` files are referenced by client

Previously, referencing a `.server` module from client code resulted in an error message like:

```txt
The requested module '/app/models/answer.server.ts' does not provide an export named 'isDateType'
```

Which was confusing because `answer.server.ts` _does_ provide the `isDateType` export,
but Remix was replacing `.server` modules with empty modules (`export {}`) for the client build.

Now, Remix explicitly fails at compile time when a `.server` module is referenced from client code
and includes dedicated error messages depending on whether the import occurs in a route or a non-route
module. The error messages also include links to relevant documentation.
- Previously, referencing a `.server` module from client code resulted in an error message like:
- `The requested module '/app/models/answer.server.ts' does not provide an export named 'isDateType'`
- This was confusing because `answer.server.ts` _does_ provide the `isDateType` export, but Remix was replacing `.server` modules with empty modules (`export {}`) for the client build
- Now, Remix explicitly fails at compile time when a `.server` module is referenced from client code and includes dedicated error messages depending on whether the import occurs in a route or a non-route module
- The error messages also include links to relevant documentation
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -623,3 +623,4 @@
- timkraut
- alexanderson1993
- signed
- VHall1
5 changes: 5 additions & 0 deletions packages/remix-dev/vite/build.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type * as Vite from "vite";
import colors from "picocolors";

import { preloadViteEsm } from "./import-vite-esm-sync";
import type { ResolvedRemixVitePluginConfig } from "./plugin";

async function extractRemixPluginConfig({
Expand Down Expand Up @@ -56,6 +57,10 @@ export async function build(
mode,
}: ViteBuildOptions
) {
// Ensure Vite's ESM build is preloaded at the start of the process
// so it can be accessed synchronously via `importViteEsmSync`
await preloadViteEsm();

// For now we just use this function to validate that the Vite config is
// targeting Remix, but in the future the return value can be used to
// configure the entire multi-step build process.
Expand Down
6 changes: 6 additions & 0 deletions packages/remix-dev/vite/dev.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type * as Vite from "vite";
import colors from "picocolors";

import { preloadViteEsm } from "./import-vite-esm-sync";

export interface ViteDevOptions {
clearScreen?: boolean;
config?: string;
Expand Down Expand Up @@ -29,6 +31,10 @@ export async function dev(
strictPort,
}: ViteDevOptions
) {
// Ensure Vite's ESM build is preloaded at the start of the process
// so it can be accessed synchronously via `importViteEsmSync`
await preloadViteEsm();

let vite = await import("vite");
let server = await vite.createServer({
root,
Expand Down
7 changes: 4 additions & 3 deletions packages/remix-serve/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ process.env.NODE_ENV = process.env.NODE_ENV ?? "production";

sourceMapSupport.install({
retrieveSourceMap: function (source) {
// get source file without the `file://` prefix or `?t=...` suffix
let match = source.match(/^file:\/\/(.*)\?t=[.\d]+$/);
// get source file with the `file://` prefix
let match = source.match(/^file:\/\/(.*)$/);
if (match) {
let filePath = url.fileURLToPath(source);
return {
url: source,
map: fs.readFileSync(`${match[1]}.map`, "utf8"),
map: fs.readFileSync(`${filePath}.map`, "utf8"),
};
}
return null;
Expand Down
7 changes: 4 additions & 3 deletions templates/express/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import sourceMapSupport from "source-map-support";

sourceMapSupport.install({
retrieveSourceMap: function (source) {
// get source file without the `file://` prefix or `?t=...` suffix
const match = source.match(/^file:\/\/(.*)\?t=[.\d]+$/);
// get source file with the `file://` prefix
const match = source.match(/^file:\/\/(.*)$/);
if (match) {
const filePath = url.fileURLToPath(source);
return {
url: source,
map: fs.readFileSync(`${match[1]}.map`, "utf8"),
map: fs.readFileSync(`${filePath}.map`, "utf8"),
};
}
return null;
Expand Down

0 comments on commit 3687e94

Please sign in to comment.