Fix ESM build #83

Merged
lucperkins merged 6 commits from fix-esm-build into main 2024-05-15 20:24:28 +00:00
lucperkins commented 2024-05-02 20:08:13 +00:00 (Migrated from github.com)

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.

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.
cole-h (Migrated from github.com) approved these changes 2024-05-02 20:13:28 +00:00
colemickens commented 2024-05-02 20:14:23 +00:00 (Migrated from github.com)

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?

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 2024-05-15 20:23:14 +00:00 (Migrated from github.com)

@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.

@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: ```typescript 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 2024-05-15 20:50:31 +00:00 (Migrated from github.com)

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)

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)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/lix-install-action#83
No description provided.