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:
Add esbuild-plugin-pnp, use ESBuild API and enable this plugin.
Create a .yarnrc and set linker to pnpm or node_modules.
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 topackage.json
entries. Without ESBuild pluginesbuild-plugin-pnp
it will not work, as ESBuild will try to find dependencies innode_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 topnpm
ornode_modules
, choose one of the strategies:esbuild-plugin-pnp
, use ESBuild API and enable this plugin..yarnrc
and set linker topnpm
ornode_modules
.