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

Node.js hook errors with direnv #1944

Open
evanleck opened this issue Mar 28, 2024 · 6 comments
Open

Node.js hook errors with direnv #1944

evanleck opened this issue Mar 28, 2024 · 6 comments
Assignees
Labels
bug Something isn't working triage Issue needs triage

Comments

@evanleck
Copy link

What happened?

I installed nodejs@20 via devbox and added direnv with devbox generate direnv and now when I cd into that directory I get this error:

direnv: loading PATH/.envrc
direnv: using devbox
PATH/.devbox/gen/scripts/.raw-hooks.sh:1: DEVBOX_COREPACK_ENABLED: unbound variable
direnv: error exit status 1

Steps to reproduce

mkdir devbox-node-repro
cd devbox-node-repro/
devbox init
devbox add nodejs@20
# Info: Adding package "nodejs@20" to devbox.json
# 
# nodejs NOTES:
# Devbox automatically configures Corepack for Nodejs when DEVBOX_COREPACK_ENABLED=1. You can install Yarn or Pnpm by adding them to your `package.json` file using # `packageManager`
# Corepack binaries will be installed in your local `.devbox` directory
# 
# This plugin creates the following helper files:
# 
# To show this information, run `devbox info nodejs`
# 
# 
devbox generate direnv
# ✓ Computed the Devbox environment.
# Success: generated .envrc file
# Success: ran `direnv allow`
# direnv: loading ~/Documents/devbox-node-repro/.envrc
# direnv: using devbox
# devbox-node-repro/.devbox/gen/scripts/.raw-hooks.sh:1: DEVBOX_COREPACK_ENABLED: unbound variable
# direnv: error exit status 1

Command

add, generate

devbox.json

{
  "$schema":  "https://raw.githubusercontent.com/jetpack-io/devbox/0.10.1/.schema/devbox.schema.json",
  "packages": ["nodejs@20"],
  "shell": {
    "init_hook": [
      "echo 'Welcome to devbox!' > /dev/null"
    ],
    "scripts": {
      "test": [
        "echo \"Error: no test specified\" && exit 1"
      ]
    }
  }
}

Devbox version

0.10.1

Nix version

nix (Nix) 2.20.5

What system does this bug occur on?

macOS (Apple Silicon)

Debug logs

No response

@evanleck evanleck added bug Something isn't working triage Issue needs triage labels Mar 28, 2024
@evanleck
Copy link
Author

Probably worth noting that I’m using fish shell.

@savil
Copy link
Collaborator

savil commented Apr 1, 2024

@evanleck which version of fish shell are you using?

@evanleck
Copy link
Author

evanleck commented Apr 1, 2024

@savil fish 3.7.1 and direnv 2.34.0

@Lagoja
Copy link
Contributor

Lagoja commented Apr 10, 2024

Hey @evanleck, I've been trying to reproduce this but I can't get the error to replicate with Fish + Direnv. Can you try the following:

  1. Update to the latest version of Devbox using devbox version update
  2. Delete the contents of your .devbox directory, then regenerate them using devbox shell.

If those don't fix your issue, can you share the contents of the file at devbox-node-repro/.devbox/gen/scripts/.raw-hooks.sh

@Lagoja Lagoja self-assigned this Apr 10, 2024
@evanleck
Copy link
Author

@Lagoja thanks for looking into the issue.

  1. Done, I'm on 0.10.4 now.
  2. Done.

Unfortunately, that didn't seem to fix the issue. The contents of .raw-hooks.sh is:

test -z $DEVBOX_COREPACK_ENABLED || corepack enable --install-directory "/Users/evan/Code/devbox-node-repro/.devbox/virtenv/nodejs/corepack-bin/"
test -z $DEVBOX_COREPACK_ENABLED || export PATH="/Users/evan/Code/devbox-node-repro/.devbox/virtenv/nodejs/corepack-bin/:$PATH"

I don't see DEVBOX_COREPACK_ENABLED anywhere in the output of env if that's of any help.

@evanleck
Copy link
Author

FWIW changing the contents of .raw-hooks to use test -v seems to fix the issue, though I'm not 100% sure it's functionally equivalent. Worth noting, test -v was introduced in bash 4.2, so this won't work on versions prior to that.

test -v DEVBOX_COREPACK_ENABLED || corepack enable --install-directory "/Users/evan/Code/devbox-node-repro/.devbox/virtenv/nodejs/corepack-bin/"
test -v DEVBOX_COREPACK_ENABLED || export PATH="/Users/evan/Code/devbox-node-repro/.devbox/virtenv/nodejs/corepack-bin/:$PATH"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Issue needs triage
Development

No branches or pull requests

3 participants