Skip to content

Commit

Permalink
fix: fix error message upon loading server-only module on the client-…
Browse files Browse the repository at this point in the history
…side (#1335)
  • Loading branch information
brillout committed Dec 8, 2023
1 parent b37f102 commit 09d362e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
15 changes: 8 additions & 7 deletions vike/node/runtime/index-deprecated.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
// TODO/v1-release: replace this with:
// assertUsage(false, "`import { something } from 'vike'` doesn't exist: instead import from 'vike/server', 'vike/client', 'vike/plugin', ...")

import { isBrowser } from '../../utils/isBrowser.js'
import { assertUsage } from '../../utils/assert.js'
assertUsage(
!isBrowser(),
"It's forbidden to `import { something } from 'vike'` on the client-side: the module 'vike' is a server-only module.",
{ showStackTrace: true }
)

export * from './index-common.js'
export * from '../../types/index-dreprecated.js'

Expand Down Expand Up @@ -48,10 +56,3 @@ assertWarning(
].join('\n'),
{ showStackTrace: true, onlyOnce: true }
)

import { isBrowser, assertUsage } from './utils.js'
assertUsage(
!isBrowser(),
"It's forbidden to `import { something } from 'vike'` in code loaded in the browser: the module 'vike' is a server-only module.",
{ showStackTrace: true }
)
9 changes: 5 additions & 4 deletions vike/node/runtime/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export * from './index-common.js'

import { isBrowser, assertUsage } from './utils.js'
import { isBrowser } from '../../utils/isBrowser.js'
import { assertUsage } from '../../utils/assert.js'
assertUsage(
!isBrowser(),
"It's forbidden to `import { something } from 'vike/server'` in code loaded on the client-side: the module 'vike/server' is a server-only module.",
"It's forbidden to `import { something } from 'vike/server'` on the client-side: the module 'vike/server' is a server-only module.",
{ showStackTrace: true }
)

export * from './index-common.js'

0 comments on commit 09d362e

Please sign in to comment.