Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Managing a copied node_modules is tricky #86

Open
dhess opened this issue Aug 5, 2021 · 5 comments
Open

Managing a copied node_modules is tricky #86

dhess opened this issue Aug 5, 2021 · 5 comments

Comments

@dhess
Copy link

dhess commented Aug 5, 2021

Is your feature request related to a problem? Please describe.

Unfortunately, it's necessary to use node_modules_mode = "copy" with create-react-app because it wants to write node_modules/.cache. (I've asked upstream for the ability to change this location: see facebook/create-react-app#11263)

Using this mode is tricky to get right. So far I've discovered the following:

Describe the solution you'd like

The project could benefit from some documentation along these lines. It might also be helpful if the shell included some npm wrapper scripts that enforce these best practices. Adding an optional shellHook to remove the node_modules directory when you're in copy mode would be helpful.

Describe alternatives you've considered

We've written some scripts to enforce these best practices in our project, but it's still easy to get something wrong, and the learning curve is a bit steep if you're not familiar with npm.

@RaitoBezarius
Copy link
Member

As I have been bitten by all these things, create-react-app writing in a cache folder, moving to Vite.js to avoid this, managing a copied node_modules through Nix, I am interested into writing the docs.

Plus, I am interested into fixing the root cause of #85 as it is seriously a pain for the developer experience :/.

@dhess
Copy link
Author

dhess commented Dec 15, 2021

Yes, we also switched to Vite from CRA, but additionally, we've also had to switch from npmlock2nix to yarn2nix for numerous other reasons, most of which are filed as issues in this project's tracker.

I think npmlock2nix has the most potential of all of the current Nix+Node.js integrations, but unfortunately, the number of outstanding issues and the apparent lack of an active maintainer mean that I don't think we'll be able to use it anytime soon. I'm not faulting anybody, by the way. I'm glad this project exists and hope that someone picks it up again someday.

@RaitoBezarius
Copy link
Member

@dhess Curious on how you used yarn2nix as I switched from that initially because it has no support for copied node_modules and has some shortcomings in regards to easy production bundle / running tests / etc, nevertheless, thank you for your experience report :)

@dhess
Copy link
Author

dhess commented Dec 15, 2021

@RaitoBezarius It has required some bespoke buildPhase overrides. I'm happy to share, but this is not the forum for it. Feel free to contact me separately.

@adisbladis
Copy link
Member

Over in https://github.com/adisbladis/buildNodeModules I've taken another approach:
I let node_modules be a directory and link individual packages into it.

To not overwrite files accidentally I took some inspiration from home-manager:
I only consider a file/directory "managed" if it's a symlink to the Nix store.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants