dream2nix icon indicating copy to clipboard operation
dream2nix copied to clipboard

Building Nota in a flake: Error: Cannot find module '.../build.mjs'

Open kentookura opened this issue 3 years ago • 1 comments

I am trying to package Nota in the following flake:

{
  inputs = {
    dream2nix.url = "github:nix-community/dream2nix";
    nota.url = "https://registry.npmjs.com/@nota-lang/nota/-/nota-0.4.12.tgz";
    nota.flake = false;
  };

  outputs = {
    self,
    dream2nix,
    nota,
  } @ inp:
    (dream2nix.lib.makeFlakeOutputs {
      systems = ["x86_64-linux"];
      config.projectRoot = ./.;
      source = nota;
      settings = [
        {
          subsystemInfo.noDev = true;
          subsystemInfo.nodejs = 18;
        }
      ];
    })
    // {
      checks = self.packages;
    };
}

After resolving impurities I get this error with nix build

> @nota-lang/[email protected] build
> node build.mjs
node:internal/modules/cjs/loader:949
  throw err;
  ^
Error: Cannot find module '/nix/store/j4s2d1qk1bk97xz7sb4anzj03hcydfyh-__at__nota-lang__slash__nota-0.4.12/lib/node_modules/@nota-lang/nota/build.mjs'
    at Module._resolveFilename (node:internal/modules/cjs/loader:946:15)
    at Module._load (node:internal/modules/cjs/loader:787:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

I suspect it has to do with the file extension .mjs as seen here but I'm not sure. Even if overriding something here would fix it, I wouldn't know how to approach it. The output of nix flake show is as expected:

git+file:///home/kento/work
├───checks
│   └───x86_64-linux
│       ├───"@nota-lang/nota": derivation '__at__nota-lang__slash__nota-0.4.12'
│       ├───default: derivation '__at__nota-lang__slash__nota-0.4.12'
│       └───resolveImpure: derivation 'resolve'
├───devShell
│   └───x86_64-linux: development environment 'nix-shell'
├───devShells
│   └───x86_64-linux
│       ├───"@nota-lang/nota": development environment 'nix-shell'
│       └───default: development environment 'nix-shell'
├───packages
│   └───x86_64-linux
│       ├───"@nota-lang/nota": package '__at__nota-lang__slash__nota-0.4.12'
│       ├───default: package '__at__nota-lang__slash__nota-0.4.12'
│       └───resolveImpure: package 'resolve'
└───projectsJson: unknown

Any help is appreciated!

kentookura avatar Sep 08 '22 10:09 kentookura

Running ls in the node_modules directory in the nix store for the nota package shows that there is no build.mjs, cross referencing this dir with https://github.com/nota-lang/nota/tree/master/packages/nota shows that many files and folders are missing, could be something wrong with the discoverer?

[bezmuth@Mishim:/nix/store/9k0wv23gnlgdhy9hbfcnsqd9jmsz4ny2-__at__nota-lang__slash__nota-0.4.12/lib/node_modules/@nota-lang/nota]$ ls -la
total 36
drwxr-xr-x   4 nixbld1 nixbld  4096 Sep 19 18:20 .
drwxr-xr-x   4 nixbld1 nixbld  4096 Sep 19 18:20 ..
drwxr-xr-x   2 nixbld1 nixbld  4096 Jan  1  1970 dist
-rw-r--r--   1 nixbld1 nixbld  1052 Jan  1  1970 LICENSE
drwxr-xr-x 290 nixbld1 nixbld 12288 Sep 19 18:20 node_modules
-rw-r--r--   1 nixbld1 nixbld  2160 Sep 19 18:20 package.json
-rw-r--r--   1 nixbld1 nixbld  2161 Sep 19 18:20 package.json.bak

bezmuth avatar Sep 19 '22 17:09 bezmuth

nota.url = "https://registry.npmjs.com/@nota-lang/nota/-/nota-0.4.12.tgz";

The problem is, that you are building from a tarball coming from npmjs.org. The releases there are usually pre-built and stripped down. Therefore you cannot build the package again.

Try building from github instead. Closing, as this is not an issue we can fix. Feel free to open a new issue if there are problems with the github release as well.

DavHau avatar Nov 09 '22 20:11 DavHau