preactjs/prefresh

@prefresh injected code fails on pnpm

liflovs opened this issue ยท 4 comments

Started project with vite + preact -> instantly got into issue using pnpm:
10:04:08 [vite] Internal server error: Failed to resolve import "@prefresh/vite/runtime" from "src\app.jsx". Does the file exist? Plugin: vite:import-analysis File: C:/Users/lflse/Projects/lifl/test/vite-project/src/app.jsx 1 | import '@prefresh/vite/runtime'; | ^ 2 | import { flushUpdates } from '@prefresh/vite/utils'; 3 | let prevRefreshReg;

Should have been fixed according to #75, a regression maybe?

Just checked on runpkg, everything looks good, wonder if it could be an issue in Windows and that plugin. Can check later

This is related to the bug I've been encountering and looked into here. TL;DR is that if prefresh/vite isn't a direct dependency of your project (e.g.: it's a dependency of Preact's vite preset), you also need to install it because of pnpm's strictness around package access/visibility.

@cyyynthia thanks, that was the issue! I guess that fact should be noted in the docs.

P.S. Borkenware - nice stuff :)

I just looked back at my attempt to fix this compatibility problem and I completely forgot Rollup accepts a 2nd argument for resolve, and this 2nd argument seems to be able to fix the problem without the problems I had in my original approach. ๐ŸŽ‰

Now the only problem I face is able to conditionally use __filename or import.meta.url for the mjs output, since bundt doesn't handle that and simply having import.meta mentioned in the file yields a SyntaxError when using commonjs. I'll open a draft PR in a bit with what I have for now.