Skip to content

css-post plugins crashes when using transformRequest without first starting a server #3798

@Pajn

Description

@Pajn

Describe the bug

While using the JS API, transformRequest can be used to get transformed versions of js/ts files without starting a server, but when doing the same on css files the css-post plugin crashes with:

❯ node server.js
(node:269183) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'get' of undefined
    at TransformContext.transform (/home/rasmus/Development/vite-repors/vite-transformRequest-css-crash-repro/node_modules/vite/dist/node/chunks/dep-bc228bbb.js:23139:56)
    at Object.transform (/home/rasmus/Development/vite-repors/vite-transformRequest-css-crash-repro/node_modules/vite/dist/node/chunks/dep-bc228bbb.js:44765:53)
    at async transformRequest (/home/rasmus/Development/vite-repors/vite-transformRequest-css-crash-repro/node_modules/vite/dist/node/chunks/dep-bc228bbb.js:59029:29)
    at async main (/home/rasmus/Development/vite-repors/vite-transformRequest-css-crash-repro/server.js:7:18)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:269183) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:269183) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Reproduction

https://github.com/Pajn/vite-transformRequest-css-crash-repro

System Info

Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers:

 npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers
npx: installed 1 in 0.727s

  System:
    OS: Linux 5.11 Ubuntu 21.04 (Hirsute Hippo)
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 8.59 GB / 30.99 GB
    Container: Yes
    Shell: 5.8 - /usr/bin/zsh
  Browsers:
    Chrome: 91.0.4472.101
    Firefox: 89.0
  npmPackages:
    vite: ^2.3.7 => 2.3.7

Used package manager: yarn

Logs

See Repro


Before submitting the issue, please make sure you do the following

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