Skip to content

Commit 88b052d

Browse files
chore: fix start scripts with cjs (#20)
1 parent 3a80e6e commit 88b052d

File tree

22 files changed

+702
-636
lines changed

22 files changed

+702
-636
lines changed

.changeset/huge-pans-do.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'rsbuild-plugin-react-router': patch
3+
---
4+
5+
do not set target when output is esm

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
22
1+
22

config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0.1",
44
"private": true,
55
"devDependencies": {
6-
"@rsbuild/core": "1.3.0-beta.2",
6+
"@rsbuild/core": "1.3.2",
77
"@rslib/core": "0.5.4",
88
"@types/node": "^22.10.1",
99
"typescript": "^5.7.2"

examples/cloudflare/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010
"typecheck": "tsc -b"
1111
},
1212
"dependencies": {
13-
"@react-router/node": "^7.4.0",
14-
"@react-router/serve": "^7.4.0",
13+
"@react-router/node": "^7.4.1",
14+
"@react-router/serve": "^7.4.1",
1515
"isbot": "^5.1.17",
1616
"react": "^19.0.0",
1717
"react-dom": "^19.0.0",
18-
"react-router": "^7.4.0"
18+
"react-router": "^7.4.1"
1919
},
2020
"devDependencies": {
2121
"@cloudflare/workers-types": "^4.20241112.0",
22-
"@react-router/cloudflare": "^7.4.0",
23-
"@react-router/dev": "^7.4.0",
24-
"@rsbuild/core": "1.3.0-beta.2",
22+
"@react-router/cloudflare": "^7.4.1",
23+
"@react-router/dev": "^7.4.1",
24+
"@rsbuild/core": "1.3.2",
2525
"@rsbuild/plugin-react": "^1.1.1",
2626
"@tailwindcss/postcss": "^4.0.0",
2727
"@types/node": "^20",

examples/custom-node-server/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@
1818
"author": "",
1919
"license": "ISC",
2020
"dependencies": {
21-
"@react-router/express": "^7.4.0",
22-
"@react-router/node": "^7.4.0",
21+
"@react-router/express": "^7.4.1",
22+
"@react-router/node": "^7.4.1",
2323
"express": "^4.21.2",
2424
"isbot": "^5.1.22",
2525
"react": "^19.0.0",
2626
"react-dom": "^19.0.0",
27-
"react-router": "^7.4.0"
27+
"react-router": "^7.4.1"
2828
},
2929
"devDependencies": {
3030
"@playwright/test": "^1.50.1",
31-
"@react-router/dev": "^7.4.0",
32-
"@rsbuild/core": "1.3.0-beta.2",
31+
"@react-router/dev": "^7.4.1",
32+
"@rsbuild/core": "1.3.2",
3333
"@rsbuild/plugin-react": "^1.1.1",
3434
"@rsdoctor/rspack-plugin": "^0.4.13",
3535
"@types/express": "^5.0.0",
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Patch for handling CJS output from the build
2+
const app = require('./build/server/static/js/app.js');
3+
4+
// Export all the top-level keys needed by react-router-serve
5+
const {
6+
assets,
7+
assetsBuildDirectory,
8+
basename,
9+
entry,
10+
future,
11+
isSpaMode,
12+
prerender,
13+
publicPath,
14+
routes,
15+
ssr
16+
} = app;
17+
18+
// Export each property individually
19+
exports.assets = assets;
20+
exports.assetsBuildDirectory = assetsBuildDirectory;
21+
exports.basename = basename;
22+
exports.entry = entry;
23+
exports.future = future;
24+
exports.isSpaMode = isSpaMode;
25+
exports.prerender = prerender;
26+
exports.publicPath = publicPath;
27+
exports.routes = routes;
28+
exports.ssr = ssr;

examples/default-template/package.json

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,38 @@
44
"type": "module",
55
"scripts": {
66
"build": "rsbuild build",
7-
"dev": "rsbuild dev",
8-
"start": "react-router-serve ./build/server/index.js",
7+
"dev": "NODE_OPTIONS=\"--experimental-vm-modules --experimental-global-webcrypto\" rsbuild dev",
8+
"start:esm": "react-router-serve ./build/server/static/js/app.js",
9+
"start:cjs": "react-router-serve ./cjs-serve-patch.cjs",
910
"typecheck": "react-router typegen && tsc",
1011
"test:e2e": "pnpm run dev & sleep 5 && playwright test",
1112
"test:e2e:debug": "playwright test --debug",
1213
"test:e2e:ui": "playwright test --ui"
1314
},
1415
"dependencies": {
15-
"@react-router/express": "^7.4.0",
16-
"@react-router/node": "^7.4.0",
17-
"@react-router/serve": "^7.4.0",
16+
"@react-router/express": "^7.4.1",
17+
"@react-router/node": "^7.4.1",
18+
"@react-router/serve": "^7.4.1",
1819
"isbot": "^5.1.17",
1920
"react": "^19.0.0",
2021
"react-dom": "^19.0.0",
21-
"react-router": "^7.4.0"
22+
"react-router": "^7.4.1"
2223
},
2324
"devDependencies": {
2425
"@playwright/test": "^1.50.1",
25-
"@react-router/dev": "^7.4.0",
26-
"@rsbuild/core": "1.3.0-beta.2",
26+
"@react-router/dev": "^7.4.1",
27+
"@rsbuild/core": "1.3.2",
2728
"@rsbuild/plugin-react": "^1.1.1",
2829
"@tailwindcss/postcss": "^4.0.0",
2930
"@types/node": "^20",
3031
"@types/react": "^19.0.1",
3132
"@types/react-dom": "^19.0.1",
33+
"cross-env": "7.0.3",
3234
"react-router-devtools": "^1.1.6",
3335
"rsbuild-plugin-react-router": "workspace:*",
36+
"string-replace-loader": "^3.1.0",
3437
"tailwindcss": "^4.0.0",
38+
"text-encoder-lite": "^2.0.0",
3539
"typescript": "^5.7.2",
3640
"vite": "^5.4.11",
3741
"vite-tsconfig-paths": "^5.1.4"

examples/epic-stack/.vscode/remix.code-snippets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,4 @@
7777
"}",
7878
],
7979
},
80-
}
80+
}

examples/epic-stack/app/root.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import { type Theme, getTheme } from './utils/theme.server.ts'
3939
import { makeTimings, time } from './utils/timing.server.ts'
4040
import { getToast } from './utils/toast.server.ts'
4141
import { useOptionalUser } from './utils/user.ts'
42-
import "./styles/tailwind.css"
42+
import './styles/tailwind.css'
4343

4444
export const links: Route.LinksFunction = () => {
4545
return [

examples/epic-stack/app/utils/db.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { remember } from '@epic-web/remember'
2-
import {PrismaClient} from '@prisma/client/index'
2+
import { PrismaClient } from '@prisma/client/index'
33

44
import chalk from 'chalk'
55

examples/epic-stack/docs/server-timing.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ export async function loader({ params }: Route.LoaderArgs) {
7878
// We have a general headers handler to save you from boilerplating.
7979
export const headers: HeadersFunction = pipeHeaders
8080
// this is basically what it does though
81-
export const headers: Route.HeadersFunction = ({ loaderHeaders, parentHeaders }) => {
81+
export const headers: Route.HeadersFunction = ({
82+
loaderHeaders,
83+
parentHeaders,
84+
}) => {
8285
return {
8386
'Server-Timing': combineServerTimings(parentHeaders, loaderHeaders), // <-- 4. Send headers
8487
}

examples/epic-stack/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@ sourceMapSupport.install({
1616
},
1717
})
1818

19-
2019
if (process.env.MOCKS === 'true') {
2120
await import('./tests/mocks/index.ts')
2221
}
2322

2423
if (process.env.NODE_ENV === 'production') {
25-
let build = (await import('./build/server/static/js/app.js'))
26-
build = build?.default || build;
24+
let build = await import('./build/server/static/js/app.js')
25+
build = build?.default || build
2726
build = build?.createApp || build
28-
build();
27+
build()
2928
} else {
3029
await import('./server/dev-build.js')
3130
}

examples/epic-stack/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@
6363
"@radix-ui/react-tooltip": "1.1.7",
6464
"@react-email/components": "0.0.32",
6565
"@react-router/express": "7.4.0",
66-
"@react-router/node": "^7.4.0",
66+
"@react-router/node": "^7.4.1",
6767
"@react-router/remix-routes-option-adapter": "7.4.0",
6868
"@remix-run/server-runtime": "2.15.3",
69-
"@rsbuild/core": "1.3.0-beta.2",
69+
"@rsbuild/core": "1.3.2",
7070
"@rsbuild/plugin-react": "1.1.1",
7171
"@sentry/node": "8.54.0",
7272
"@sentry/profiling-node": "8.54.0",
@@ -100,7 +100,7 @@
100100
"qrcode": "1.5.4",
101101
"react": "19.0.0",
102102
"react-dom": "19.0.0",
103-
"react-router": "^7.4.0",
103+
"react-router": "^7.4.1",
104104
"remix-auth": "3.7.0",
105105
"remix-auth-github": "1.7.0",
106106
"remix-utils": "8.1.0",
@@ -120,7 +120,7 @@
120120
"@epic-web/config": "1.16.5",
121121
"@faker-js/faker": "9.4.0",
122122
"@playwright/test": "1.50.1",
123-
"@react-router/dev": "^7.4.0",
123+
"@react-router/dev": "^7.4.1",
124124
"@sentry/vite-plugin": "3.1.2",
125125
"@sly-cli/sly": "1.14.0",
126126
"@testing-library/dom": "10.4.0",

examples/epic-stack/rsbuild.config.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { defineConfig } from '@rsbuild/core';
2-
import { pluginReact } from '@rsbuild/plugin-react';
3-
import { pluginReactRouter } from 'rsbuild-plugin-react-router';
4-
import 'react-router';
1+
import { defineConfig } from '@rsbuild/core'
2+
import { pluginReact } from '@rsbuild/plugin-react'
3+
import { pluginReactRouter } from 'rsbuild-plugin-react-router'
4+
import 'react-router'
55

66
export default defineConfig(() => {
7-
return {
8-
output: {
9-
externals: [
10-
'better-sqlite3',
11-
'express',
12-
]
13-
},
14-
plugins: [pluginReactRouter({customServer: true, serverOutput: 'commonjs'}), pluginReact()],
15-
};
16-
});
7+
return {
8+
output: {
9+
externals: ['better-sqlite3', 'express'],
10+
},
11+
plugins: [
12+
pluginReactRouter({ customServer: true, serverOutput: 'commonjs' }),
13+
pluginReact(),
14+
],
15+
}
16+
})

examples/epic-stack/server/dev-build.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ import { createRsbuild, loadConfig } from '@rsbuild/core'
22
import 'dotenv/config'
33

44
async function startServer() {
5-
const config = await loadConfig()
6-
const rsbuild = await createRsbuild({
7-
rsbuildConfig: config.content,
8-
})
9-
const devServer = await rsbuild.createDevServer()
5+
const config = await loadConfig()
6+
const rsbuild = await createRsbuild({
7+
rsbuildConfig: config.content,
8+
})
9+
const devServer = await rsbuild.createDevServer()
1010

11-
// Load the bundle first to get createApp
12-
if (!devServer.environments?.node) {
13-
throw new Error('Node environment not found in dev server')
14-
}
11+
// Load the bundle first to get createApp
12+
if (!devServer.environments?.node) {
13+
throw new Error('Node environment not found in dev server')
14+
}
1515

16-
const bundle = await devServer.environments.node.loadBundle('app')
17-
const { createApp } = bundle
18-
const app = await createApp(devServer)
16+
const bundle = await devServer.environments.node.loadBundle('app')
17+
const { createApp } = bundle
18+
const app = await createApp(devServer)
1919

20-
devServer.connectWebSocket({ server: app })
20+
devServer.connectWebSocket({ server: app })
2121
}
2222

2323
void startServer().catch(console.error)

examples/epic-stack/server/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ sourceMapSupport.install({
3030
},
3131
})
3232

33-
3433
const MODE = process.env.NODE_ENV ?? 'development'
3534
const IS_PROD = MODE === 'production'
3635
const IS_DEV = MODE === 'development'

examples/epic-stack/server/utils/monitoring.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {PrismaInstrumentation} from '@prisma/instrumentation'
1+
import { PrismaInstrumentation } from '@prisma/instrumentation'
22
import * as Sentry from '@sentry/node'
33
import { nodeProfilingIntegration } from '@sentry/profiling-node'
44

examples/federation/epic-stack-remote/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@
6666
"@radix-ui/react-tooltip": "1.1.7",
6767
"@react-email/components": "0.0.32",
6868
"@react-router/express": "7.4.0",
69-
"@react-router/node": "^7.4.0",
69+
"@react-router/node": "^7.4.1",
7070
"@react-router/remix-routes-option-adapter": "7.4.0",
7171
"@remix-run/server-runtime": "2.15.3",
72-
"@rsbuild/core": "1.3.0-beta.2",
72+
"@rsbuild/core": "1.3.2",
7373
"@rsbuild/plugin-react": "1.1.1",
7474
"@sentry/node": "8.54.0",
7575
"@sentry/profiling-node": "8.54.0",
@@ -103,7 +103,7 @@
103103
"qrcode": "1.5.4",
104104
"react": "19.0.0",
105105
"react-dom": "19.0.0",
106-
"react-router": "^7.4.0",
106+
"react-router": "^7.4.1",
107107
"remix-auth": "3.7.0",
108108
"remix-auth-github": "1.7.0",
109109
"remix-utils": "8.1.0",
@@ -122,7 +122,7 @@
122122
"@epic-web/config": "1.16.5",
123123
"@faker-js/faker": "9.4.0",
124124
"@playwright/test": "1.50.1",
125-
"@react-router/dev": "^7.4.0",
125+
"@react-router/dev": "^7.4.1",
126126
"@sly-cli/sly": "1.14.0",
127127
"@testing-library/dom": "10.4.0",
128128
"@testing-library/jest-dom": "6.6.3",

examples/federation/epic-stack/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@
6666
"@radix-ui/react-tooltip": "1.1.7",
6767
"@react-email/components": "0.0.32",
6868
"@react-router/express": "7.4.0",
69-
"@react-router/node": "^7.4.0",
69+
"@react-router/node": "^7.4.1",
7070
"@react-router/remix-routes-option-adapter": "7.4.0",
7171
"@remix-run/server-runtime": "2.15.3",
72-
"@rsbuild/core": "1.3.0-beta.2",
72+
"@rsbuild/core": "1.3.2",
7373
"@rsbuild/plugin-react": "1.1.1",
7474
"@sentry/node": "8.54.0",
7575
"@sentry/profiling-node": "8.54.0",
@@ -103,7 +103,7 @@
103103
"qrcode": "1.5.4",
104104
"react": "19.0.0",
105105
"react-dom": "19.0.0",
106-
"react-router": "^7.4.0",
106+
"react-router": "^7.4.1",
107107
"remix-auth": "3.7.0",
108108
"remix-auth-github": "1.7.0",
109109
"remix-utils": "8.1.0",
@@ -122,7 +122,7 @@
122122
"@epic-web/config": "1.16.5",
123123
"@faker-js/faker": "9.4.0",
124124
"@playwright/test": "1.50.1",
125-
"@react-router/dev": "^7.4.0",
125+
"@react-router/dev": "^7.4.1",
126126
"@sly-cli/sly": "1.14.0",
127127
"@testing-library/dom": "10.4.0",
128128
"@testing-library/jest-dom": "6.6.3",

0 commit comments

Comments
 (0)