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: use createRequire to require svelte.config.cjs in esm project #142

Merged
merged 7 commits into from
Aug 16, 2021
Merged

fix: use createRequire to require svelte.config.cjs in esm project #142

merged 7 commits into from
Aug 16, 2021

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Aug 16, 2021

Fixes #141

Import .cjs config file if app is running in type: module.

Also added a few more tests for loading different config files.

@bluwy bluwy marked this pull request as draft August 16, 2021 04:12
@bluwy bluwy marked this pull request as ready for review August 16, 2021 05:04
@bluwy
Copy link
Member Author

bluwy commented Aug 16, 2021

Initially went with the import("svelte.config.cjs") strategy, which surprisingly works, but apparently the timestamp query cache bust doesn't actually work for cjs only and keeps returning the same reference when updating the svelte config. Luckily the CI caught this.

So I changed to using createRequire instead if we're in esm (checked via import.meta.url). And that seems to work without too much overhead.

@dominikg
Copy link
Member

I couldn't find docs that mention import.meta.url is only set when it's running in esm mode, but it makes sense. Thanks!

@dominikg dominikg changed the title feat: try import cjs config fix: use createRequire to require svelte.config.cjs in esm project Aug 16, 2021
@dominikg dominikg merged commit 4540d96 into sveltejs:main Aug 16, 2021
@github-actions github-actions bot mentioned this pull request Aug 16, 2021
@bluwy bluwy deleted the gh-141 branch August 16, 2021 11:46
@github-actions github-actions bot mentioned this pull request Jul 13, 2022
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.

TypeError: __require.resolve is not a function with svelte.config.cjs in an esm project
2 participants