Skip to content

Revert back to require for use in templates #1320

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

amcgavin
Copy link

@amcgavin amcgavin commented Jul 3, 2025

This PR aimed to remove require in favour of import.

A side effect of this was that require no longer works correctly inside templates because it is now an async function. Since the template is rendered synchronously, it is no longer possible to import anything from inside a template.

This PR restores that functionality, which was introduced in version 4.0.4.

Thanks!

Copy link

changeset-bot bot commented Jul 3, 2025

⚠️ No Changeset found

Latest commit: 3ff5247

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

@amcgavin
Copy link
Author

amcgavin commented Jul 3, 2025

I'm not sure if this warrants a minor version bump or if patch is acceptable

@amcgavin
Copy link
Author

@smorimoto could you please have a look when you get the chance?

@smorimoto smorimoto requested a review from Copilot July 11, 2025 06:37
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR restores synchronous require calls in templates by reverting recent changes that replaced require with async import.

  • Removed async from requireFnFromTemplate
  • Replaced await import(...) with require(...) for both file paths and package names
Comments suppressed due to low confidence (4)

src/templates-worker.ts:77

  • Consider updating any JSDoc or TypeScript signatures to reflect that this function is now synchronous rather than returning a Promise.
  requireFnFromTemplate = (packageOrPath: string) => {

src/templates-worker.ts:82

  • Using require on an ES module may yield an object with a default property. You might want to return module.default ?? module to handle both CJS and ESM modules correctly.
      return require(

src/templates-worker.ts:91

  • [nitpick] For packages that resolve to ESM, consider using createRequire from Node's module API or adding tests to confirm that requiring works as expected in both CJS and ESM contexts.
    return require(packageOrPath);

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.

1 participant