You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I discovered this while using the @preact/preset-vite plugin. After accidentally deleting preact-render-to-string, I encountered some strange errors during the build, instead of being directly informed that this dependency was missing.
[preact:prerender] d is not a function
✓ built in 120ms
error during build:
TypeError: d is not a function
Due to the vague error messages, it took me a while to realize the absence of preact-render-to-string. After checking the implementation of @preact/preset-vite and preact-iso, I found that the code built by vite seems to have some incorrect transformations. For example, the following code in preact-iso
In dist/prerender-xB4rff8V.js, you can see renderToString is transformed into an empty object, which causes subsequent errors.
I'm not sure if the specific error is vite, rollup, or the preact-vite plugin, but the error being thrown when the peer dependency is not found is incorrect.
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
While looking into further, I realized that this "silently empty object" behavior only applies to default import. If it were named import, vite/rollup build would "correctly" fails.
"noSuchLib" is not exported by "__vite-optional-peer-dep:no-such-lib:some-dep", imported by "node_modules/.pnpm/file+some-dep/node_modules/some-dep/index.js".
file: /home/projects/github-wbqa6s/node_modules/.pnpm/file+some-dep/node_modules/some-dep/index.js:2:9
1: // ...
2: import { noSuchLib } from 'no-such-lib';
^
There is another export default {} fallback behavior, which is used for builtin module import (e.g. import fs from "node:fs). In this case, Vite has a warning during resolveId phase:
[plugin:vite:resolve] Module "node:fs" has been externalized for browser compatibility, imported by "/home/projects/github-wbqa6s/src/index.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
Describe the bug
Original issue: preactjs/preset-vite#101
I discovered this while using the
@preact/preset-vite
plugin. After accidentally deletingpreact-render-to-string
, I encountered some strange errors during the build, instead of being directly informed that this dependency was missing.[preact:prerender] d is not a function ✓ built in 120ms error during build: TypeError: d is not a function
vite configuration
src/index.tsx
Due to the vague error messages, it took me a while to realize the absence of
preact-render-to-string
. After checking the implementation of@preact/preset-vite
andpreact-iso
, I found that the code built by vite seems to have some incorrect transformations. For example, the following code in preact-isogets transformed into
I can even reproduce this without the
@preact/preset-vite
plugin, just by modifying the vite configurationIn dist/prerender-xB4rff8V.js, you can see
renderToString
is transformed into an empty object, which causes subsequent errors.I'm not sure if the specific error is vite, rollup, or the preact-vite plugin, but the error being thrown when the peer dependency is not found is incorrect.
Related discussions: #15725 (reply in thread)
Reproduction
https://github.com/rxliuli/preact-ssg-demo.git
Steps to reproduce
System Info
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: