nushell / nushell/nu_scripts

`modules/background_task/task.nu`: can not use a module inside closure in current directory.

Open
#1,280 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Nushell
Stars
1.3k
Forks
323
Avg merge
2h 55m
Merged PRs (30d)
3

Description

Given tmp.nu in home directory, or any other directory except /tmp
I cannot run task spawn with the following closure:

task spawn { print $env.PWD; use tmp.nu }

When I run task log, it reports the following error message:

Error: nu::parser::module_not_found

  x Module not found.
   ,-[/tmp/tmp.Id6nNnlTch-nu-task:1:22]
 1 |  print $env.PWD; use tmp.nu
   :                      ^^^|^^
   :                         `-- module tmp.nu not found
   `----
  help: module files and their paths must be available before your script is
        run as parsing occurs before anything is evaluated

I believe it's because task spawn save the closure into a temporary file, which makes nushell doesn't try to load module from current directory. I don't think it's a nushell issue, maybe we can just change task.nu to fix it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in modules/background_task/task.nu and reproduce the reported task spawn closure with tmp.nu in the current directory, then inspect how the closure is saved and run. Done means task spawn can use a module from the current directory and task log no longer reports module_not_found.

Written by the indexing model from the issue text.

Assessment

Tech stack
shell
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.