Skip to content

Cannot build typescript ssr file #4887

@JakeGinnivan

Description

@JakeGinnivan

Describe the bug

When trying to get SSR working, the sample project will not build in production mode. I think the code which sets process.env.NODE_ENV is being replaced, so that variable can't be assigned?

$ /Users/jakeginnivan/_code/vite-ts-ssr/vite-project/node_modules/.bin/vite build --outDir dist/server --ssr src/entry-server.ts
vite v2.5.6 building SSR bundle for production...
✓ 62 modules transformed.
[commonjs] Assigning to rvalue (33444:4) in /Users/jakeginnivan/_code/vite-ts-ssr/vite-project/node_modules/vite/dist/node/chunks/dep-9f74b403.js
file: /Users/jakeginnivan/_code/vite-ts-ssr/vite-project/node_modules/vite/dist/node/chunks/dep-9f74b403.js:33444:4
33442: 
33443:   if (!ctx.env) {
33444:     process.env.NODE_ENV = 'development';
           ^
33445:   }

My naive guess is that what is actually happening is 'production' = 'development'?

It is possible this is another variation of #3229, but thought I would open a fresh issue because the symptoms are a bit different.

Reproduction

https://github.com/JakeGinnivan/vite-ssr-build-issue

Then run yarn && yarn vite build --outDir dist/server --ssr src/entry-server.ts.

System Info

npx: installed 1 in 1.542s

  System:
    OS: macOS 11.5.2
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 258.38 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.3 - /usr/local/opt/node@14/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.13 - /usr/local/opt/node@14/bin/npm
  Browsers:
    Chrome: 93.0.4577.63
    Firefox: 91.0.2
    Safari: 14.1.2
  npmPackages:
    vite: ^2.5.4 => 2.5.6

Used Package Manager

yarn

Logs

--debug flag offered no additional info over the above error

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions