aleclarson / vite-tsconfig-paths

Support for TypeScript's path mapping in Vite
MIT License
1.3k stars 48 forks source link

Usage with yarn pnp #94

Closed eyeball-bot closed 1 year ago

eyeball-bot commented 1 year ago

Hi,

is it possible to use this plugin with yarn pnp? currently i'm getting the following error when starting vite:

Error: vite-tsconfig-paths tried to access vite, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: vite (via "vite/package.json")

any idea how to solve this?

thanks

arempe93 commented 1 year ago

Here's a workaround that did the job for me:

# .yarnrc.yml

packageExtensions:
  vite-tsconfig-paths@*:
    peerDependencies:
      vite: "*"

I think this could be adapted into a general fix, just needs a better version number for the peer dep (not *)

DiFuks commented 1 year ago

I see that Vite was excluded from peer dependencies in this issue https://github.com/aleclarson/vite-tsconfig-paths/issues/89

But also I see an explicit import from Vite https://github.com/aleclarson/vite-tsconfig-paths/blob/master/src/index.ts#L8

Because of this, in pnp mode, the plugin stops working

We are making a library for creating a boilerplate (similar to create-react-app), which includes this plugin. And we just can't force all our users to do the workaround as @arempe93 pointed out

It seems the most logical solution would be to make Vite peer a dependency, but an optional one:

"peerDependencies": { 
  "vite": "^4.0.0"
},
"peerDependenciesMeta": {
  "vite": {
    "optional": true
  }
}
aleclarson commented 1 year ago

@DiFuks PR is very welcome, thanks

DiFuks commented 1 year ago

@aleclarson https://github.com/aleclarson/vite-tsconfig-paths/pull/100

aleclarson commented 1 year ago

Fixed in v4.0.6

Thanks @DiFuks

viceice commented 1 year ago

I still get this error. 😕

Error: vite-tsconfig-paths tried to access vite (a peer dependency) but it isn't provided by your application; this makes the require call ambiguous and unsound.

Required package: vite (via "vite/package.json")
Required by: vite-tsconfig-paths@virtual:8fe8e73e4af70ba096693cc74c354e4c9005b052d376fa7b6797025ae28760335def907c17d9995f6836709b832f51b25de90a4f09ea95ae730e10e9bf3077c0#npm:4.2.0 (via /mnt/c/Users/kriese/projects/gh/containerbase/base/.yarn/__virtual__/vite-tsconfig-paths-virtual-9fcbf3395b/0/cache/vite-tsconfig-paths-npm-4.2.0-af5eeb1a7e-73a8467de7.zip/node_modules/vite-tsconfig-paths/dist/index.mjs)
Ancestor breaking the chain: containerbase@workspace:.