Skip to content

Test setup/utils files importing server module gives: Server-only module referenced by client #13216

Open
@kentcdodds

Description

@kentcdodds

Reproduction

git clone https://github.com/epicweb-dev/epic-stack.git
cd epic-stack
git checkout vitest-config
npm install
npm run test

System Info

System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Max
    Memory: 2.20 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.15.0 - ~/n/bin/node
    Yarn: 1.22.17 - ~/n/bin/yarn
    npm: 10.8.1 - ~/n/bin/npm
    pnpm: 8.15.6 - /opt/homebrew/bin/pnpm
    bun: 1.1.10 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 127.1.68.137
    Chrome: 127.0.6533.120
    Safari: 17.5

Used Package Manager

npm

Expected Behavior

I expect the tests to run without issue

Actual Behavior

I get the following error:

 FAIL  app/routes/users+/$username.test.tsx [ app/routes/users+/$username.test.tsx ]
Error: Server-only module referenced by client

    '#app/utils/env.server.ts' imported by 'tests/setup/setup-test-env.ts'

  See https://remix.run/docs/en/main/guides/vite#splitting-up-client-and-server-code

Test files are a special case.

I'm thinking anything out of the app directory should be ignored by this module import check. That would resolve my issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions