vitejs / vite-plugin-react-swc

Speed up your Vite dev server with SWC
MIT License
778 stars 50 forks source link

Unable to resolve plugins in pnpm with `hoist=false` #135

Closed liningpan closed 10 months ago

liningpan commented 11 months ago

I'm trying to use @graphql-codegen/client-preset-swc-plugin in a pnpm / Bazel monorepo. It appears that with hoist=false, which is also the behavior of the Bazel rules. I get an error like this

Error: Cannot find module '@graphql-codegen/client-preset-swc-plugin'

I know storybook had similar issues before, and this is how they resolve modules with absolute paths

import { join, dirname } from "path";

function getAbsolutePath(value: string): any {
  return dirname(require.resolve(join(value, "package.json")));
}
const config: StorybookConfig = {
  stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
  addons: [
    getAbsolutePath("@storybook/addon-links"),
  ...
}
ArnaudBarre commented 10 months ago

Hi,

I not sure this plugin is the best place to fix this kind of resolution issues. I need to get a better understanding at the issue but this plugin is just calling SWC like most other tools would do and I think it should be either better supported by SWC or pnpm