dream2nix icon indicating copy to clipboard operation
dream2nix copied to clipboard

NodeJS translator: missing dependency

Open fufexan opened this issue 3 years ago • 6 comments

Me and @a-kenji were trying to package Misskey using dream2nix here.

The error we got:
packages__slash__client-unknown> building
packages__slash__client-unknown> > @ build /nix/store/jc3sjifirk4vi6p29sr3pqf63nwww9z5-packages__slash__client-unknown/lib/node_modules/packages/client
packages__slash__client-unknown> > vite build
packages__slash__client-unknown> ✘ [ERROR] Could not resolve "../../locales"
packages__slash__client-unknown>     vite.config.ts:5:20:
packages__slash__client-unknown>       5 │ import locales from '../../locales';
packages__slash__client-unknown>         ╵                     ~~~~~~~~~~~~~~~
packages__slash__client-unknown> ✘ [ERROR] Could not resolve "../../package.json"
packages__slash__client-unknown>     vite.config.ts:6:17:
packages__slash__client-unknown>       6 │ import meta from '../../package.json';
packages__slash__client-unknown>         ╵                  ~~~~~~~~~~~~~~~~~~~~
packages__slash__client-unknown> failed to load config from /nix/store/jc3sjifirk4vi6p29sr3pqf63nwww9z5-packages__slash__client-unknown/lib/node_modules/packages/client/vite.config.ts
packages__slash__client-unknown> error during build:
packages__slash__client-unknown> Error: Build failed with 2 errors:
packages__slash__client-unknown> vite.config.ts:5:20: ERROR: Could not resolve "../../locales"
packages__slash__client-unknown> vite.config.ts:6:17: ERROR: Could not resolve "../../package.json"
packages__slash__client-unknown>     at failureErrorWithLog (/nix/store/lqxk5wx7d0mq8na5awch9zny8wb6kny2-esbuild-0.14.48/lib/node_modules/esbuild/lib/main.js:1605:15)
packages__slash__client-unknown>     at /nix/store/lqxk5wx7d0mq8na5awch9zny8wb6kny2-esbuild-0.14.48/lib/node_modules/esbuild/lib/main.js:1251:28
packages__slash__client-unknown>     at runOnEndCallbacks (/nix/store/lqxk5wx7d0mq8na5awch9zny8wb6kny2-esbuild-0.14.48/lib/node_modules/esbuild/lib/main.js:1034:63)
packages__slash__client-unknown>     at buildResponseToResult (/nix/store/lqxk5wx7d0mq8na5awch9zny8wb6kny2-esbuild-0.14.48/lib/node_modules/esbuild/lib/main.js:1249:7)
packages__slash__client-unknown>     at /nix/store/lqxk5wx7d0mq8na5awch9zny8wb6kny2-esbuild-0.14.48/lib/node_modules/esbuild/lib/main.js:1358:14
packages__slash__client-unknown>     at /nix/store/lqxk5wx7d0mq8na5awch9zny8wb6kny2-esbuild-0.14.48/lib/node_modules/esbuild/lib/main.js:666:9
packages__slash__client-unknown>     at handleIncomingPacket (/nix/store/lqxk5wx7d0mq8na5awch9zny8wb6kny2-esbuild-0.14.48/lib/node_modules/esbuild/lib/main.js:763:9)
packages__slash__client-unknown>     at Socket.readFromStdout (/nix/store/lqxk5wx7d0mq8na5awch9zny8wb6kny2-esbuild-0.14.48/lib/node_modules/esbuild/lib/main.js:632:7)
packages__slash__client-unknown>     at Socket.emit (events.js:400:28)
packages__slash__client-unknown>     at addChunk (internal/streams/readable.js:293:12)
packages__slash__client-unknown> npm ERR! code ELIFECYCLE
packages__slash__client-unknown> npm ERR! errno 1
packages__slash__client-unknown> npm ERR! @ build: `vite build`
packages__slash__client-unknown> npm ERR! Exit status 1
packages__slash__client-unknown> npm ERR!
packages__slash__client-unknown> npm ERR! Failed at the @ build script.
packages__slash__client-unknown> npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
packages__slash__client-unknown>
packages__slash__client-unknown> npm ERR! A complete log of this run can be found in:
packages__slash__client-unknown> npm ERR!     /build/.npm/_logs/2022-09-05T10_11_11_430Z-debug.log

It seems that the os-locale dependency can't be found. We tried both the package-lock and the yarn-lock translators, and we also tried overriding the source with the appropriate package injection https://github.com/fufexan/misskey-d2n/tree/overrides. It looks like dream2nix doesn't try to fetch the injected package that we set.

fufexan avatar Sep 05 '22 10:09 fufexan

I can build the misskey package fine on the branch you linked. It doesn't seem to produce anything that I can run though, so I'm not sure if it actually works or not. I just did nix build .#misskey and then put in the missing hash for os-locale, then it built fine.

90-008 avatar Sep 05 '22 12:09 90-008

My bad, I forgot to also post the build command. We were trying to build the packages/client package, which was causing the above error.

It doesn't seem to produce anything that I can run though

Right, there are no binaries, but you can run npm run start which also won't work because it's missing the xev package (not pkgs.xorg.xev).

fufexan avatar Sep 05 '22 12:09 fufexan

I think that build error might be pointing to something else? It tries to build /nix/store/fbdjs66j36cdckljcwqvdkwdgd9y590g-packages__slash__client-unknown/lib/node_modules/packages/client, but then tries to access ../../package.json but that relative path does not exist, because where ../.. points to only has a packages directory. So it looks like it's trying to access the top-level package.json of misskey, but can't because it doesn't exist (same with locales). Maybe you could try putting those files where it expects them to be, but not sure if that would work and even if it would it sounds like a hacky solution. Maybe dream2nix should just build these using the same source, the full misskey repo itself, instead of separating the sources for the packages. For example this is what the Rust builders do if the source is a Cargo workspace. Maybe nodejs has something similar, or at least the user should be able to specify something for this.

90-008 avatar Sep 05 '22 13:09 90-008

Yeah several people already ran into that kind of problem. We should make source isolation optional, so sub-packages can access each others source.

DavHau avatar Sep 08 '22 10:09 DavHau

Has there been any progress on this? Any way I can help?

fufexan avatar Sep 24 '22 10:09 fufexan

@fufexan I created #307 with some more description on what needs to be done here. Feel free to reply on that issue if something is not clear, or you need help in some way.

DavHau avatar Sep 27 '22 11:09 DavHau