DeterminateSystems / nix-installer-action

The Github Action for the Determinate Nix Installer
https://github.com/determinateSystems/nix-installer
GNU Lesser General Public License v2.1
158 stars 16 forks source link

Fix ESM build #83

Closed lucperkins closed 4 months ago

lucperkins commented 4 months ago

A gotcha that we need to be mindful of in the future. Whenever we use these built-in Node.js libs we need to import the node:* variants lest we get bitten by the require(...) thing.

colemickens commented 4 months ago

I don't quite know what "the require(...) thing." is. Or I did and forgot, probably that.

I take it this slipped through locally but was an issue when deployed? Is there some way to catch it locally or CI?

lucperkins commented 4 months ago

@colemickens Basically when you're running in Node.js you need to import the node:* versions of core libraries. node:path, for example, is basically a wrapper around path that looks like this:

declare module "node:path" {
    import path = require("path");
    export = path;
}

This turns an ordinary lib into a module that can be, in turn, compiled into an ESM module. If you don't have this wrapper and you just declare, say, import { join } from "path" then things crap out at runtime for reasons I admittedly do not fully understand.

cole-h commented 4 months ago

Reverted in https://github.com/DeterminateSystems/nix-installer-action/pull/86 because namespace runners were failing with:

::group::Configuring the Docker shim as the Nix Daemon's process supervisor
Configuring the Docker shim as the Nix Daemon's process supervisor
  ##[debug]Loading image: determinate-nix-shim:latest...
  ##[debug]open /home/runner/work/magic-nix-cache/docker-shim/arm64.tar.gz: no such file or directory
  Error: Error: The process '/usr/bin/docker' failed with exit code 1

(https://github.com/DeterminateSystems/magic-nix-cache/actions/runs/9102189543/job/25021651676)