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: show a migration error when using the default export #105

Merged
merged 1 commit into from
Feb 2, 2023

Conversation

stipsan
Copy link
Member

@stipsan stipsan commented Feb 2, 2023

This improves the migration experience, instead of a generic error if attempting to use the default export it'll show a specific error:

import sanityClient from '@sanity/client'

const client = sanityClient()
// throws: TypeError: The default export of @sanity/client has been deprecated. Use the named export `createClient` instead
import SanityClient from '@sanity/client'

const client = new SanityClient()
// throws: TypeError: The default export of @sanity/client has been deprecated. Use the named export `createClient` instead
const {default: sanityClient} = require('@sanity/client')
const {default: SanityClient} = require('@sanity/client')

const client = sanityClient()
const client = new SanityClient()
// throws: TypeError: The default export of @sanity/client has been deprecated. Use the named export `createClient` instead

Unable to make this work without risking weird side-effects:

const sanityClient = require('@sanity/client')

const client = sanityClient()
// throws: Uncaught TypeError: sanityClient is not a function

And in TypeScript instead of a @sanity/client doesn't have a default export you'll see:
image

@stipsan stipsan force-pushed the improve-migration-experience branch from f061dce to 320703c Compare February 2, 2023 13:55
@stipsan stipsan merged commit adb582e into main Feb 2, 2023
@stipsan stipsan deleted the improve-migration-experience branch February 2, 2023 14:31
@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2023

🎉 This PR is included in version 5.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant