nix-community / npmlock2nix

nixify npm based packages [maintainer=@andir]
Apache License 2.0
130 stars 42 forks source link

Problems with `node_modules` copy mode and `next-js` #163

Open Radvendii opened 2 years ago

Radvendii commented 2 years ago

In the build function, we reference nm (the generated node_modules) in two ways. One is in buildInputs, and the other is by copying / symlinking it into the current directory in the preConfigure phase. Is there a reason we do both of these?

It seems to be causing problems when using next-js. It's also possible I am diagnosing the problem wrong; I am not very familiar with any of the pieces here.


The error I get is:

Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:

  • You might have mismatching versions of React and the renderer (such as React DOM)
  • You might be breaking the Rules of Hooks
  • You might have more than one copy of React in the same app See for tips about how to debug and fix this problem.

I think the relevant point is "You might have more than one copy of React in the same app." Since the copy it is finding in the error message is the one in the nix store, rather than in the current directory.

When I override as follows:

(pkgs.npmlock2nix.build {
  ...
}).overrideAttrs (old: {
  buildInputs = [ pkgs.nodejs ]; # note that the old contents of `buildInputs` (namely `nm`) is being overwritten
  preConfigure = old.preConfigure + ''
    chmod u+x node_modules/.bin/*
  '';
})

it works.