Skip to content

Commit

Permalink
fix(serve): update usage error to support ESM (#7400)
Browse files Browse the repository at this point in the history
  • Loading branch information
markdalgleish authored Sep 13, 2023
1 parent 1071209 commit 6430a57
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/remix-serve-esm-usage-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/serve": patch
---

Update remix-serve usage error message to support ESM projects
11 changes: 1 addition & 10 deletions docs/file-conventions/remix-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,6 @@ main module. If specified, Remix will compile this file along with your
application into a single file to be deployed to your server. This file can use
either a `.js` or `.ts` file extension.

## serverBuildDirectory

<docs-warning>This option is deprecated and will likely be removed in a future
stable release. Use [`serverBuildPath`][server-build-path]
instead.</docs-warning>

The path to the server build, relative to `remix.config.js`. Defaults to
"build". This needs to be deployed to your server.

## serverBuildPath

The path to the server build file, relative to `remix.config.js`. This file
Expand Down Expand Up @@ -150,7 +141,7 @@ module.exports = {
appDirectory: "app",
assetsBuildDirectory: "public/build",
publicPath: "/build/",
serverBuildDirectory: "build",
serverBuildPath: "build/index.js",
ignoredRouteFiles: ["**/.*"],
serverDependenciesToBundle: [
/^rehype.*/,
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/migrating-react-router-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ In your `package.json` file, update your scripts to use `remix` commands instead
"scripts": {
"build": "remix build",
"dev": "remix dev",
"start": "remix-serve build",
"start": "remix-serve build/index.js",
"typecheck": "tsc"
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The Remix compiler will not do any type checking (it simply removes the types).
"scripts": {
"build": "remix build",
"dev": "remix dev",
"start": "remix-serve build",
"start": "remix-serve build/index.js",
"typecheck": "tsc"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion docs/other-api/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ For example, you may have it hardcoded in your `server.js` file.
If you are using `remix-serve` as your app server, you can use its `--port` flag to set the app server port:

```sh
remix dev -c "remix-serve --port 8000 ./build"
remix dev -c "remix-serve --port 8000 ./build/index.js"
```

In contrast, the `remix dev --port` option is an escape-hatch for users who need fine-grain control of network ports.
Expand Down
8 changes: 5 additions & 3 deletions docs/other-api/serve.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,31 @@ Remix is designed for you to own your server, but if you don't want to set one u

```sh
remix-serve <server-build-path>
# e.g.
remix-serve build/index.js
```

## `PORT` environment variable

You can change the port of the server with an environment variable.

```sh
PORT=4000 npx remix-serve <server-build-path>
PORT=4000 npx remix-serve build/index.js
```

## `HOST` environment variable

You can configure the hostname for your Express app via `process.env.HOST` and that value will be passed to the internal [`app.listen`][express-listen] method when starting the server.

```sh
HOST=127.0.0.1 npx remix-serve build/
HOST=127.0.0.1 npx remix-serve build/index.js
```

## Development Environment

Depending on `process.env.NODE_ENV`, the server will boot in development or production mode.

The `server-build-path` needs to point to the `serverBuildDirectory` defined in `remix.config.js`.
The `server-build-path` needs to point to the `serverBuildPath` defined in `remix.config.js`.

Because only the build artifacts (`build/`, `public/build/`) need to be deployed to production, the `remix.config.js` is not guaranteed to be available in production, so you need to tell Remix where your server build is with this option.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"build": "remix build",
"dev": "remix dev",
"start": "remix-serve build"
"start": "remix-serve build/index.js"
},
"dependencies": {},
"devDependencies": {},
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-dev/__tests__/fixtures/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"build": "remix build",
"dev": "remix dev",
"start": "remix-serve build",
"start": "remix-serve build/index.js",
"typecheck": "tsc"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-dev/__tests__/fixtures/stack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"build": "remix build",
"dev": "remix dev",
"start": "remix-serve build"
"start": "remix-serve build/index.js"
},
"dependencies": {},
"devDependencies": {},
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-serve/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function run() {

if (!buildPathArg) {
console.error(`
Usage: remix-serve <build-dir>`);
Usage: remix-serve <server-build-path> - e.g. remix-serve build/index.js`);
process.exit(1);
}

Expand Down

0 comments on commit 6430a57

Please sign in to comment.