rails / jsbundling-rails

Bundle and transpile JavaScript in Rails with esbuild, rollup.js, bun, or Webpack.
MIT License
849 stars 147 forks source link

Detect the use of Yarn PnP when using esbuild #112

Closed TakaiSaisei closed 1 year ago

TakaiSaisei commented 2 years ago

It seems that jsbundling-rails knows absolutely nothing about Yarn versions above 1.x. If Yarn version globally set to 2.x or 3.x, and rails new myapp -j esbuild is called - JS bundling does not work unless you fix it yourself. Yarn Modern uses Plug'n'Play as default installing option and it breaks Rails environment.

For reference: Yarn Plug'n'Play drops old idea of having node_modules dir in app folder - instead it caches all dependencies and generates .pnp.cjs file that maps them to package.json entries. Without ESBuild plugin esbuild-plugin-pnp it will not work, as ESBuild will try to find dependencies in node_modules folder.

As I think we should look for Yarn version and/or Yarn nodeLinker config - if Yarn version is higher than 1.x, nodeLinker is not explicitly set to pnpm or node_modules, choose one of the strategies:

dhh commented 1 year ago

We should enforce use of Yarn 1.x. Feel free to investigate.