Skip to content

Commit a88fb2d

Browse files
authored
fix(rsc): replace non-optimized server cjs warning with debug only log (#698)
1 parent f0359c4 commit a88fb2d

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

packages/plugin-rsc/e2e/basic.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,20 @@ test.describe('dev-non-optimized-cjs', () => {
5858
)
5959
})
6060

61-
const f = useFixture({ root: 'examples/basic', mode: 'dev' })
61+
const f = useFixture({
62+
root: 'examples/basic',
63+
mode: 'dev',
64+
cliOptions: {
65+
env: {
66+
DEBUG: 'vite-rsc:cjs',
67+
},
68+
},
69+
})
6270

6371
test('show warning', async ({ page }) => {
6472
await page.goto(f.url())
65-
expect(f.proc().stderr()).toContain(
66-
`Found non-optimized CJS dependency in 'ssr' environment.`,
73+
expect(f.proc().stderr()).toMatch(
74+
/non-optimized CJS dependency in 'ssr' environment.*@vitejs\/test-dep-cjs\/index.js/,
6775
)
6876
})
6977
})

packages/plugin-rsc/examples/react-router/cf/vite.config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,11 @@ export default defineConfig({
4545
},
4646
ssr: {
4747
optimizeDeps: {
48-
include: ['react-router > cookie', 'react-router > set-cookie-parser'],
4948
exclude: ['react-router'],
5049
},
5150
},
5251
rsc: {
5352
optimizeDeps: {
54-
include: ['react-router > cookie', 'react-router > set-cookie-parser'],
5553
exclude: ['react-router'],
5654
},
5755
},

packages/plugin-rsc/src/plugins/cjs.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import path from 'node:path'
55
import fs from 'node:fs'
66
import * as esModuleLexer from 'es-module-lexer'
77
import { transformCjsToEsm } from '../transforms/cjs'
8+
import { createDebug } from '@hiogawa/utils'
9+
10+
const debug = createDebug('vite-rsc:cjs')
811

912
export function cjsModuleRunnerPlugin(): Plugin[] {
10-
// use-sync-external-store is known to work fine so don't show warning
11-
const warnedPackages = new Set<string>(['use-sync-external-store'])
13+
const warnedPackages = new Set<string>()
1214

1315
return [
1416
{
@@ -43,9 +45,8 @@ export function cjsModuleRunnerPlugin(): Plugin[] {
4345
// warning once per package
4446
const packageKey = extractPackageKey(id)
4547
if (!warnedPackages.has(packageKey)) {
46-
this.warn(
47-
`Found non-optimized CJS dependency in '${this.environment.name}' environment. ` +
48-
`It is recommended to add the dependency to 'environments.${this.environment.name}.optimizeDeps.include'.`,
48+
debug(
49+
`non-optimized CJS dependency in '${this.environment.name}' environment: ${id}`,
4950
)
5051
warnedPackages.add(packageKey)
5152
}

0 commit comments

Comments
 (0)