| 10 Nov 2023 |
peter-lustig | Lily Foster: could you help me with packaging my nodejs app? These are the requirements:
You will need the output directory, the project's package.json, and the production dependencies in node_modules to run the application. Production dependencies can be generated by copying the package.json and package-lock.json and then running npm ci --omit dev (you can skip this step if your app doesn't have any dependencies). You can then start your app with this command:
node build
Development dependencies will be bundled into your app using Rollup. To control whether a given package is bundled or externalised, place it in devDependencies or dependencies respectively in your package.json.
This is what I have:
buildInputs = with pkgs; [
nodejs_20
];
src = ./.;
npmDepsHash = "sha256-mTpjBKTIJkYVj2jrH5lF/n3Axceak4L60ZDQECQhGew=";
npmBuild = "npm run build";
npmInstallFlags = [ "--omit dev" ];
installPhase = ''
mkdir $out
cp -r build/* $out
cp package.json $out
cp package-lock.json $out
'';
| 22:26:37 |
peter-lustig | * Lily Foster: could you help me with packaging my nodejs app? These are the requirements:
*First,
You will need the output directory, the project's package.json, and the production dependencies in node_modules to run the application. Production dependencies can be generated by copying the package.json and package-lock.json and then running npm ci --omit dev (you can skip this step if your app doesn't have any dependencies). You can then start your app with this command:
node build Development dependencies will be bundled into your app using Rollup. To control whether a given package is bundled or externalised, place it in devDependencies or dependencies respectively in your package.json.*
This is what I have:
buildInputs = with pkgs; [
nodejs_20
];
src = ./.;
npmDepsHash = "sha256-mTpjBKTIJkYVj2jrH5lF/n3Axceak4L60ZDQECQhGew=";
npmBuild = "npm run build";
npmInstallFlags = [ "--omit dev" ];
installPhase = ''
mkdir $out
cp -r build/* $out
cp package.json $out
cp package-lock.json $out
'';
| 22:26:53 |
peter-lustig | I think there are already few faults in there, but this is the first error I have:
sh: line 1: vite: command not found | 22:27:56 |
peter-lustig | (build is output directory, just to give context) | 22:28:40 |
Lily Foster | In reply to @peter-lustig:matrix.org
Lily Foster: could you help me with packaging my nodejs app? These are the requirements:
*First,
You will need the output directory, the project's package.json, and the production dependencies in node_modules to run the application. Production dependencies can be generated by copying the package.json and package-lock.json and then running npm ci --omit dev (you can skip this step if your app doesn't have any dependencies). You can then start your app with this command:
node build Development dependencies will be bundled into your app using Rollup. To control whether a given package is bundled or externalised, place it in devDependencies or dependencies respectively in your package.json.*
This is what I have:
buildInputs = with pkgs; [
nodejs_20
];
src = ./.;
npmDepsHash = "sha256-mTpjBKTIJkYVj2jrH5lF/n3Axceak4L60ZDQECQhGew=";
npmBuild = "npm run build";
npmInstallFlags = [ "--omit dev" ];
installPhase = ''
mkdir $out
cp -r build/* $out
cp package.json $out
cp package-lock.json $out
'';
I don't think npmBuild is doing anything there (it's not a valid arg?) and npm install implicitly has --omit=dev, but what that will do is prune dev dependencies (like vite) also when installing deps... | 22:30:04 |
Lily Foster | If you want to prune deps, you should npm prune --omit=dev yourself | 22:30:33 |
Lily Foster | wait the more i'm reading this the less sense it makes | 22:31:44 |
Lily Foster | are you able to share more info on the npm package itself? | 22:31:55 |
peter-lustig | In reply to @lily:lily.flowers are you able to share more info on the npm package itself? This is what I am following now, just trying to do that stuff with nix: https://kit.svelte.dev/docs/adapter-node#deploying | 22:32:23 |
Lily Foster | (and you shouldn't need modules if you use rollup, right?) | 22:32:29 |
Lily Foster | i'm pretty sure buildNpmPackage will do the right thing without trying to recreate what these docs are suggesting | 22:33:24 |
Lily Foster | you might just need to add build as a dir for npm package in your package.json | 22:33:35 |
Lily Foster | and then it should handle everything else | 22:33:42 |
Lily Foster | * and then buildNpmPackage should handle everything else | 22:33:47 |
peter-lustig | In reply to @lily:lily.flowers you might just need to add build as a dir for npm package in your package.json so what could I omit in buildNpmPackage? | 22:34:03 |
Lily Foster | these docs are confusing because if it's using rollup, why is it saying you need node_modules? | 22:34:28 |
Lily Foster | unless i'm misremembering what rollup does | 22:34:35 |
Lily Foster | also that buildInputs is likely not doing anything either | 22:35:00 |
Lily Foster | this might just be fine:
buildNpmPackage {
src = ./.;
npmDepsHash = "sha256-mTpjBKTIJkYVj2jrH5lF/n3Axceak4L60ZDQECQhGew=";
installPhase = ''
cp -r build $out
'';
nodejs = nodejs_20;
}
| 22:35:37 |
Lily Foster | actually maybe move build somewhere more useful | 22:36:09 |
Cobalt | In reply to @lily:lily.flowers
this might just be fine:
buildNpmPackage {
src = ./.;
npmDepsHash = "sha256-mTpjBKTIJkYVj2jrH5lF/n3Axceak4L60ZDQECQhGew=";
installPhase = ''
cp -r build $out
'';
nodejs = nodejs_20;
}
Isn't this one missing the {pre,post}install hooks? | 22:36:21 |
Lily Foster | In reply to @c0ba1t:matrix.org Isn't this one missing the {pre,post}install hooks? it is, yes. but it's an out-of-tree package so i didn't bother 😅 | 22:37:07 |
peter-lustig | does that nodejs even exist? | 22:37:09 |
peter-lustig |  Download image.png | 22:37:10 |
Cobalt | It does on 23.05 https://search.nixos.org/packages?channel=23.05&from=0&size=50&sort=relevance&type=packages&query=nodejs | 22:37:36 |
Cobalt | * It does on 23.05: https://search.nixos.org/packages?channel=23.05&from=0&size=50&sort=relevance&type=packages&query=nodejs | 22:37:50 |
peter-lustig | In reply to @c0ba1t:matrix.org It does on 23.05: https://search.nixos.org/packages?channel=23.05&from=0&size=50&sort=relevance&type=packages&query=nodejs yeah, but i have nerver seen it being used like this | 22:38:02 |
peter-lustig | I guess I need pkgs.nodejs_20 | 22:38:13 |
Lily Foster | In reply to @lily:lily.flowers actually maybe move build somewhere more useful maybe something like this if you want a bin you can just execute
buildNpmPackage {
src = ./.;
npmDepsHash = "sha256-mTpjBKTIJkYVj2jrH5lF/n3Axceak4L60ZDQECQhGew=";
nodejs = pkgs.nodejs_20;
nativeBuildInputs = [ pkgs.makeWrapper ];
installPhase = ''
mkdir -p $out/lib/node_modules
cp -r build $out/lib/node_modules/sveltepackage
makeWrapper ${pkgs.nodejs-slim_20}/bin/node $out/bin/sveltepackage \
--add-flags $out/lib/node_modules/sveltepackage
'';
}
| 22:40:36 |
Lily Foster | (note you need to be on like nixpkgs master to get the nodejs arg on buildNpmPackage | 22:40:54 |