adisbladis / buildNodeModules

An experiment in improving node packaging for nix. Dead simple.
43 stars 2 forks source link

How to use it. #7

Open zaheerahmad33 opened 1 month ago

zaheerahmad33 commented 1 month ago

I am creating a default.nix in /fixtures/kitchen_sink

let pkgs = import <nixpkgs> {};
bnm = import ~/buildNodeModules { pkgs = pkgs; lib = pkgs.lib; };
inherit (bnm) buildNodeModules fetchNodeModules hooks;
in
pkgs.stdenv.mkDerivation {
  pname = "my-website";
  version = "0.1.0";

  src = ./.;

  nativeBuildInputs = [
    hooks.npmConfigHook
    pkgs.nodejs
    pkgs.nodejs.passthru.python # for node-gyp
    pkgs.npmHooks.npmBuildHook
    pkgs.npmHooks.npmInstallHook
  ];

  nodeModules = fetchNodeModules {
    packageRoot = ./.;
  };
}

I am not sure what's I'm doing wrong here!

@adisbladis @ursi can you please guide me on how to use this project?

ursi commented 1 month ago

What is the non-nix thing you are trying to accomplish in nix, npm run build? or do you just want to build node_modules like npm install?

zaheerahmad33 commented 1 month ago

@ursi for now I am building node_modules like npm install. I was able to run the project but getting error

Error:

npm ERR! code ENOTCACHED
npm ERR! request to https://registry.npmjs.org/@swc%2fcore failed: cache mode is 'only-if-cached' but no cached response is available.

npm ERR! A complete log of this run can be found in: /tmp/nix-build-my-website-0.1.0.drv-0/.npm/_logs/2024-05-11T09_43_15_972Z-debug-0.log

error: builder for '/nix/store/27aq60pf10gqzhjfbf10zb9871chykvk-my-website-0.1.0.drv' failed with exit code 1;
       last 25 log lines:
       > npm WARN node_modules/@swc/core
       > npm WARN   dev @swc/core@"~1.3.85" from the root project
       > npm WARN   3 more (@swc-node/register, nx, ts-node)
       > npm WARN
       > npm WARN Could not resolve dependency:
       > npm WARN peerOptional @swc/core@">=1.2.50" from ts-node@10.9.1
       > npm WARN node_modules/ts-node
       > npm WARN   dev ts-node@"10.9.1" from the root project
       > npm WARN   2 more (@nx/js, jest-config)
       > npm WARN ERESOLVE overriding peer dependency
       > npm WARN While resolving: @swc-node/core@1.13.1
       > npm WARN Found: @swc/core@undefined
       > npm WARN node_modules/@swc/core
       > npm WARN   dev @swc/core@"~1.3.85" from the root project
       > npm WARN
       > npm WARN Could not resolve dependency:
       > npm WARN peer @swc/core@">= 1.4.13" from @swc-node/core@1.13.1
       > npm WARN node_modules/@swc-node/register/node_modules/@swc-node/core
       > npm WARN   @swc-node/core@"^1.10.6" from @swc-node/register@1.6.8
       > npm WARN   node_modules/@swc-node/register
       > npm ERR! code ENOTCACHED
       > npm ERR! request to https://registry.npmjs.org/@swc%2fcore failed: cache mode is 'only-if-cached' but no cached response is available.
ursi commented 1 month ago

here is an example of building node_modules https://github.com/purs-nix/purs-nix/blob/8caa40f7fe69b9fcd05baae04c4ec9eb43953e2e/examples/foreign-dependencies/flake.nix#L46-L51