Skip to content

Add import.meta.directory and import.meta.file properties #47756

@SetTrend

Description

@SetTrend

What is the problem this feature will solve?

Currently, import.meta.url gets the current file's absolute file path in URL format. This format cannot be used with node:path for creating absolute file paths.

The proposed additional properties will provide the current file's file path details in a format that can be used with node:path.

What is the feature you are proposing to solve the problem?

import.meta should provide the following additional properties:

  1. directory
  2. file

Example

Given the following absolute file path (on Windows):

C:\user\repos\mine\main.js

import.meta would provide the following properties:

{
  "directory"  : "C:\\user\\repos\\mine\\"
  "file" : "main.js"
  "url"  : "file:///C:/user/repos/mine/main.js"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    esmIssues and PRs related to the ECMAScript Modules implementation.feature requestIssues that request new features to be added to Node.js.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions