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: ESM error when using SST #1279

Closed
wants to merge 1 commit into from
Closed

Conversation

angeloashmore
Copy link
Member

Context

This PR fixes an issue when @slicemachine/manager is used in an SST application.

The Solution

Move prettier into a dynamic import. Prettier declares __dirname in its code, which conflicts with SST's __dirname definition.

Impact / Dependencies

N/A

Checklist before requesting a review

  • I hereby declare my code ready for review.
  • If it is a critical feature, I have added tests.
  • The CI is successful.
  • If there could backward compatibility issues, it has been discussed and planned.

Copy link

linear bot commented Jan 30, 2024

Copy link

vercel bot commented Jan 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
slice-machine ✅ Ready (Inspect) Visit Preview Jan 30, 2024 1:38am

@@ -16,6 +16,8 @@ export const format = async (
filePath: string,
options?: FormatOptions,
): Promise<string> => {
const prettier = await import("prettier");
Copy link
Collaborator

@bapmrl bapmrl Jan 30, 2024

Choose a reason for hiding this comment

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

❓ Can dynamically loading the prettier module impact the performance of the format function? I'm thinking of what could happen with a large amount of consecutive calls.

Copy link
Member Author

Choose a reason for hiding this comment

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

Dynamic imports shouldn't significantly impact performance unless the module contains a lot of code. Prettier is large, so it's possible it could cause slow-downs, but I don't think it would be significant enough to worry about it.

Typically only the first load takes longer. I think Node.js's import cache speeds up subsequent imports.

@angeloashmore
Copy link
Member Author

It turns out this change didn't work. Instead, we need to include prettier in node_modules in the sm-api SST app.

@angeloashmore angeloashmore deleted the aa/dt-1891-fix-esm branch February 2, 2024 00:14
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