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

typescript: defined tsconfig.json paths not consistent with reality #158

Open
nrdxp opened this issue May 23, 2022 · 2 comments
Open

typescript: defined tsconfig.json paths not consistent with reality #158

nrdxp opened this issue May 23, 2022 · 2 comments
Labels
bug Something isn't working nodejs

Comments

@nrdxp
Copy link

nrdxp commented May 23, 2022

I have a wip package effort going on here:
https://github.com/input-output-hk/cardano-js-sdk/tree/dn2-wip

After working out several other issues during the build, I've reached a point where I keep getting strange type errors during the typescript compiler run. After digging into the node_modules folder, and looking through the various tsconfig.json of various dependencies, I've noticed that they have various path definitions point to non existent locations (inside the source derivation), meaning the compiler cannot find all the type definitions, meaning ultimately that the build fails.

To reproduce one of the errors I'm seeing run: nix build .\#@cardano-sdk/core -L from that branch I linked above.

As a concrete example of a bad path, you can enter the failed build's source derivation and cd into node_modules/@bcoe/v8-coverage/tsconfig.json and see it has the following defintion:

    "typeRoots": [
      "src/lib/custom-typings",
      "node_modules/@types"
    ]

But it's local node_modules folder is completely empty

@tgunnoe
Copy link

tgunnoe commented May 23, 2022

The error I get is:

src/Cardano/types/TxSubmissionErrors.ts:10:14 - error TS2742: The inferred type of 'TxSubmissionErrors' cannot be named without a reference to '@cardano-sdk/core/node_modules/@cardano-ogmios/schema'. This is likely not portable. A type annotation is necessary.

For what its worth, I had the same problem using hardhat with dream2nix. This was a month or two back for me, so I don't remember precisely. But I added a blank import for the listed reference.

here was my solution: https://github.com/tgunnoe/hardhat-flake/blob/master/flake.nix#L33-L54

I got your package to build with the following updated flake:

  {
    inputs = {
      dream2nix.url = "github:nix-community/dream2nix";
    };
   
    outputs = {
      self,
      dream2nix,
      nixpkgs,
    } @ inp: let
      inherit (nixpkgs.legacyPackages.x86_64-linux) pkgs;
      inherit (pkgs) lib;
   
      dream2nix = inp.dream2nix.lib2.init {
        systems = ["x86_64-linux"];
        config.projectRoot = ./.;
      };
    in
      (dream2nix.makeFlakeOutputs {
        source = ./.;
        settings = [
          {subsystemInfo.noDev = false;}
        ];
        packageOverrides =
          builtins.mapAttrs (
            n: _:
              if lib.hasPrefix "@" n
              then {
                add-inputs.buildInputs = old: old ++ [self.packages.x86_64-linux.cardano-sdk.dependencies.type  script];
                add-type-notation = {
                  prePatch = ''
                    echo -e "import _ from \"@cardano-sdk/core/node_modules/@cardano-ogmios/schema\";\n$(cat s  rc/Cardano/types/TxSubmissionErrors.ts)" > src/Cardano/types/TxSubmissionErrors.ts
                  '';
                };
                copy-modules.installMethod = "copy";
                copy-tsconfig.preBuild = ''
                  cp ${./tsconfig.json} $nodeModules/tsconfig.json
                  chmod +w -R node_modules
                  ${pkgs.fd}/bin/fd tsconfig.tsbuildinfo node_modules -x ${pkgs.gnused}/bin/sed -i 's|../../..  /node_modules|../../..|g'
                '';
              }
              else {}
          )
          self.packages.x86_64-linux;
   
        inject = {
        };
   
        sourceOverrides = _: {
        };
      })
      // {
        devShell.x86_64-linux = pkgs.mkShell {
          nativeBuildInputs = with pkgs.nodejs-14_x.pkgs; [yarn self.packages.x86_64-linux.cardano-sdk.depende  ncies.typescript pkgs.nodejs-14_x];
        };
      };
  }

I realize this is a work around and there's a missing issue to be addressed in dream2nix.

@tgunnoe
Copy link

tgunnoe commented May 23, 2022

I think it has something to do with typescript or npm expecting only local references, and it receives references from outside of its local node_modules.

Also, you don't need to add typescript as a buildInput to the packageOverrides if typescript is already defines in the devDependencies of package.json, because dream2nix builds with them in scope.

FYI, I am porting a very similar ecosystem to nix using dream2nix and have mostly completed the prodedure. Working on runtimes and integration tests for it at the moment: https://github.com/bobanetwork/boba/blob/nix/flake.nix

So feel free to message me on matrix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working nodejs
Projects
None yet
Development

No branches or pull requests

3 participants