SSR: `Cannot read property 'get' of undefined` [cssModulesCache] since v2.3.4
See original GitHub issueDescribe the bug
After updating to v2.3.4, I get this error when trying to render a Svelte file with CSS in development mode:
TypeError: Cannot read property 'get' of undefined
at TransformContext.transform (/my-project/node_modules/vite/src/node/plugins/css.ts:256:51)
at Object.transform (/my-project/node_modules/vite/src/node/server/pluginContainer.ts:495:43)
at transformRequest (/my-project/node_modules/vite/src/node/server/transformRequest.ts:128:27)
at instantiateModule (/my-project/node_modules/vite/src/node/ssr/ssrModuleLoader.ts:68:6) {
plugin: 'vite:css-post',
id: '/my-project/src/components/SettingsSidebar.svelte?svelte&type=style&lang.css',
pluginCode: '.SidebarNav.s-6BsyqWO9S_5d{color:black}.s-6BsyqWO9S_5d{}'
}
The error points to this line: https://github.com/vitejs/vite/blob/b6d12f71c1dbd5562f25bc2c32c44eed32b27e94/packages/vite/src/node/plugins/css.ts, so the undefined
of the error message probably refers to the cssModulesCache
.
The line has recently been changed for this PR: https://github.com/vitejs/vite/pull/3516/files
Reproduction
I hope that this change was recent enough and the problem is obvious enough that I don’t have to assemble a reproduction. If you still need one, tell me!
System Info
Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers
:
System:
OS: macOS 11.3.1
CPU: (16) x64 Intel(R) Xeon(R) W-2140B CPU @ 3.20GHz
Memory: 805.53 MB / 32.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.16.1 - ~/.nvm/versions/node/v14.16.1/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 6.14.12 - ~/.nvm/versions/node/v14.16.1/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Browsers:
Chrome: 90.0.4430.212
Edge: 90.0.818.66
Firefox: 87.0
Firefox Developer Edition: 89.0
Safari: 14.1
Safari Technology Preview: 14.2
npmPackages:
vite: ^2.3.4 => 2.3.4
Used package manager: npm
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top Results From Across the Web
typeerror: cannot read property 'descendant' of undefined
TypeError: Cannot read properties of undefined (reading 'Descendant') I ... This exception is triggered after the npm run build command in the Dockerfile....
Read more >Cannot read property 'type' of undefined in AOS animation
After checking your code, I think the version you are using for AOS is not stable. Here you go: import React, { useState,...
Read more >Avoiding those dang cannot read property of undefined errors
Uncaught TypeError : Cannot read property 'foo' of undefined. The dreaded error we all hit at some point in JavaScript development.
Read more >Webpack Error: Cannot read property .toWebpackConfig of ...
TypeError: Cannot read property 'toWebpackConfig' of undefined ... After pushing to Heroku to confirm this worked in production, I get the following error:....
Read more >Uncaught TypeError: Cannot read property 'from' of undefined
I am creating client side app using vitejs bundler and this is the error I am getting: dgraph-js-http: ^21.3.1 Note: I tried this...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@AlonMiz Thanks for the hint, that helped me to fix it in my app!
My problem was that I had this code on the server for SSR:
This used to work, but since Vite v2.3.4, I got the mentioned error.
But if I explicitely set the
middlewareMode
, it works again:I currently don’t have time to provide a more complete reproduction than that, sorry. 😦 In any case, I can at least work around the error for now and continue with my app. 🚀
This issue has been locked since it has been closed for more than 14 days.
If you have found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest Vite version. If you have any other comments you should join the chat at Vite Land or create a new discussion.