preactjs / preset-vite

Preset for using Preact with the vite bundler
https://npm.im/@preact/preset-vite
MIT License
260 stars 26 forks source link

Compat alias not working for pnpm link project #94

Closed jennydaman closed 10 months ago

jennydaman commented 10 months ago

I am trying to create a React component library and use pnpm link to use it in a demo project. In the demo project, I am trying to use Preact (while the component library uses React).

https://github.com/jennydaman/preact-vite-pnpm-link-bug

In this minimal reproduction case, I created some projects by running

pnpm create vite preact-demo --template preact-ts
pnpm create vite react-demo --template react-ts

I also created a third package which exports ExampleComponent:

import React, { useState } from "react";

const ExampleComponent: React.FC = () => {
  const [counter, setCounter] = React.useState(0);
  return (<>
    <h1>this is ExampleComponent.</h1>
    <button onClick={() => setCounter(counter + 1)}>ExampleComponent counter: {counter}</button>
  </>)
}

export { ExampleComponent };

To {preact,react}-demo/src/App.tsx I added the code

<ExampleComponent />

Then linked the projects:

cd preact-demo
pnpm install
pnpm link ../component

cd ../react-demo
pnpm install
pnpm link ../component

The react-demo works as-expected, however preact-demo fails:

[plugin:vite:import-analysis] Failed to resolve import "react" from "../niivue-react/src/NiivueCanvas.tsx". Does the file exist?
rschristian commented 10 months ago

Don't use symlinks to test libraries, that's full of unexpected and non-representative behaviors.

Use something like yalc instead.

rschristian commented 10 months ago

Closing, let me know if you are still having issues and we can reopen/look into them.