Skip to content

Make it possible to reference reusable module files from scripts #7247

@Veetaha

Description

@Veetaha

Related problem

The problem is described in the PR comment #6150 (comment). It looks to me that PR was intended to solve this problem, but I can't get this working.

Here is a simple example of having a script file and a module

# scripts/lib.nu

export def foo [] {}
# scripts/main.nu

use lib.nu foo

foo

We can't call the script like this:

nu ./scripts/main.nu
Error: nu::parser::module_not_found (link)

  × Module not found.
   ╭─[./scripts/main.nu:2:1]
 2 │ 
 3 │ use lib.nu foo
   ·     ───┬──
   ·        ╰── module not found
 4 │ 
   ╰────
  help: module files and their paths must be available before your script is run as parsing occurs before anything is evaluated

Describe the solution you'd like

I propose to make all use, overlay, source inside any .nu file reference paths relative to the script file itself instead of the process CWD. This is necessary to make robust split into multiple files and good shareable modules.

Describe alternatives you've considered

No response

Additional context and details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions