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

fix: Fix invalid usage of import.meta.dirname Update run.js #5370

Closed
wants to merge 1 commit into from

Conversation

mdqst
Copy link
Contributor

@mdqst mdqst commented Dec 13, 2024

Description

The code incorrectly uses import.meta.dirname to resolve the path to specs.json. However, import.meta.dirname does not exist in Node.js, leading to the error:

Cannot read property 'dirname' of undefined

This update replaces the invalid import.meta.dirname usage with the correct approach, combining path.dirname and import.meta.url. The updated logic ensures compatibility with Node.js and properly resolves the directory path.

Changes made

  • Updated the default value for the spec option to:
    path.resolve(path.dirname(new URL(import.meta.url).pathname), 'specs.json')

Why this change is necessary

The previous implementation would fail in environments using native ES modules in Node.js. The corrected approach leverages import.meta.url, which is the proper method to determine the current file's location, and ensures that the directory resolution is handled accurately.

Testing

Tested the updated logic to confirm the path to specs.json resolves correctly in both standard Node.js environments and those using ES module syntax.

PR Checklist

  • Tests
  • Documentation
  • Changeset entry (run npx changeset add)

Copy link

changeset-bot bot commented Dec 13, 2024

⚠️ No Changeset found

Latest commit: b23d4f8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@Amxx
Copy link
Collaborator

Amxx commented Dec 13, 2024

import.meta.dirname is valid since node 20

@Amxx Amxx closed this Dec 20, 2024
@mdqst mdqst deleted the patch-6 branch December 20, 2024 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants