Fails to build @cloudflare/wrangler@beta (due to NPM workspaces?)
NPM now has a "workspace" concept, where multiple packages reside in the same repository, and share the same package-lock.json. Wrangler2 (the rewrite that is known by NPM as @cloudflare/wrangler@beta, hosted in a different repository from the stable version) fails to build, and.. maybe it's because it's using a workspace?
Here's a couple of attempts to build wrangler2 using npmlock2nix:
$ nix build .#theSubDir
error: [npmlock2nix] A valid dependency consists of at least the resolved and integrity field. Missing one or both of them for `@ampproject/remapping`. The object I got looks like this: {"requires":{"@jridgewell/trace-mapping":"^0.2.2","sourcemap-codec":"1.4.8"},"version":"2.0.2"}
(use '--show-trace' to show detailed location information)
$ nix build .#hybrid
error: [npmlock2nix] A valid dependency consists of at least the resolved and integrity field. Missing one or both of them for `@ampproject/remapping`. The object I got looks like this: {"requires":{"@jridgewell/trace-mapping":"^0.2.2","sourcemap-codec":"1.4.8"},"version":"2.0.2"}
(use '--show-trace' to show detailed location information)
$ nix build .#theRoot
error: [npmlock2nix] A valid dependency consists of at least the resolved and integrity field. Missing one or both of them for `@ampproject/remapping`. The object I got looks like this: {"requires":{"@jridgewell/trace-mapping":"^0.2.2","sourcemap-codec":"1.4.8"},"version":"2.0.2"}
(use '--show-trace' to show detailed location information)
flake.nix:
{
description = "Wrangler2";
inputs = {
nixpkgs.url = github:nixos/nixpkgs;
flake-utils.url = github:numtide/flake-utils;
npmlock2nix = {
url = github:nix-community/npmlock2nix;
flake = false;
};
wrangler2 = {
# this is tag [email protected], which is rejected by Nix likely due to the at sign
url = "github:cloudflare/wrangler2/3789b164ec5f56e59545bb7059e20e8543e0d95b";
flake = false;
};
};
outputs = { self, nixpkgs, flake-utils, ... }@inputs:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
system = "x86_64-linux";
};
npmlock2nix = import inputs.npmlock2nix.outPath {
pkgs = pkgs;
};
in
{
packages.theRoot = npmlock2nix.build {
src = inputs.wrangler2.outPath;
buildCommands = [ "cd packages/wrangler && npm run build" ];
installPhase = "cp -r dist $out";
};
packages.hybrid = npmlock2nix.build {
src = inputs.wrangler2.outPath;
packageJson = "${inputs.wrangler2.outPath}/packages/wrangler/package.json";
packageLockJson = "${inputs.wrangler2.outPath}/package-lock.json";
buildCommands = [ "cd packages/wrangler && npm run build" ];
installPhase = "cp -r dist $out";
};
packages.theSubDir = npmlock2nix.build {
src = "${inputs.wrangler2.outPath}/packages/wrangler";
packageJson = "${inputs.wrangler2.outPath}/packages/wrangler/package.json";
packageLockJson = "${inputs.wrangler2.outPath}/package-lock.json";
buildCommands = [ "npm run build" ];
installPhase = "cp -r dist $out";
};
}
);
}
Oh the "integrity" field issue might be due to changes in npm? See https://github.com/svanderburg/node2nix/issues/238#issuecomment-942838431
another example in the wild: portiaui/package-lock.json
{
"name": "portia-ui",
"version": "2.0.0-alpha",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"npm": {
"dependencies": {
"async-some": {
"version": "1.0.2",
"integrity": "sha1-TYqBYg1ZWHkbW5j4AtMgd3bpVQk=",
"dev": true,
"requires": {
"dezalgo": "^1.0.2"
}
},
error: [npmlock2nix] A valid dependency consists of at least the resolved and integrity field. Missing one or both of them for `async-some`. The object I got looks like this: {"dev":true,"integrity":"sha1-TYqBYg1ZWHkbW5j4AtMgd3bpVQk=","requires":{"dezalgo":"^1.0.2"},"version":"1.0.2"}
workaround: use the default registry
wget https://registry.npmjs.org/async-some/-/async-some-1.0.2.tgz
sha1sum async-some-1.0.2.tgz | cut -d' ' -f1 | xxd -r -ps | base64
# TYqBYg1ZWHkbW5j4AtMgd3bpVQk=