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

Fails to build @cloudflare/wrangler@beta (due to NPM workspaces?) #144

Open
tv42 opened this issue Feb 23, 2022 · 2 comments · May be fixed by #158
Open

Fails to build @cloudflare/wrangler@beta (due to NPM workspaces?) #144

tv42 opened this issue Feb 23, 2022 · 2 comments · May be fixed by #158

Comments

@tv42
Copy link

tv42 commented Feb 23, 2022

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";
        };
      }
    );
}
@tv42
Copy link
Author

tv42 commented Feb 23, 2022

Oh the "integrity" field issue might be due to changes in npm? See svanderburg/node2nix#238 (comment)

@milahu
Copy link
Contributor

milahu commented Apr 14, 2022

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=

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

Successfully merging a pull request may close this issue.

2 participants