Are you running with rails s? Try switching to ./bin/dev. If I’m not mistaking that option will install bootstrap in a way that requires a yarn process that watches and updates the files.
Can you share your .yarnrc.yml file? I had the same issue when using the Yarn Plug’n’Play feature (https://yarnpkg.com/features/pnp). I fixed the problem by going back to node-modules. Add nodeLinker: node-modules to your .yarnrc.yml file.
In my case, I had to install the appropriate requirements before running the rails new command.
It needs:
nodejs (apt install nodejs may install version 12 that is too old !)
npx
yarn
Here is a link to new rails app using Bootsrap and Postgresql: Constantin De La Roche / app-bootsrap · GitLab - look at the README.md that contains the instructions to generate your own new app.
I have this issue and I think it’s because there’s no node_modules folder. I kind of would rather not give up on this and embrace plug’n’play. Does anyone know how to resolve this? I’m using yarn 4.1.0.
I think you faced this issue because you were using Yarn Modern.
Yarn Modern won’t create a node_modules folder and so the import statement (from node_modules) fails.
You probably instead have a .pnp.cjs file.
There is probably a clue to a preferred solution in this SO response (though I didn’t understand it /couldn’t get it to work). Instead you can try what @ Tomasz Pajor alluded to (noting this gives up on the benefits of Yarn PnP):
Delete the pnp files
Create a .yarnrc.yml file in the root directory
add nodeLinker: node-modules to .yarnrc.yml
run $yarn install (node_modules folder should appear)
restart server
I just followed these steps for a new Rails 8 app:
$rails new myapp -c bootstrap
got the ‘can’t find stylesheet to import’ error.
I followed the steps above and bootstrap now works.