Skip to content

clipboard-copy causing problems in svelte kit #669

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

Closed
OG84 opened this issue Jun 5, 2021 · 3 comments
Closed

clipboard-copy causing problems in svelte kit #669

OG84 opened this issue Jun 5, 2021 · 3 comments

Comments

@OG84
Copy link

OG84 commented Jun 5, 2021

with [email protected] my svelte kit app fails with

ReferenceError: module is not defined
    at /node_modules/clipboard-copy/index.js?v=cb435601:4:1

As a workaround I had to add clipboard-copy to the optimizeDeps in svelte config.

const config = {
  preprocess: preprocess(),

  kit: {
    ...
    vite: {
      optimizeDeps: {
		include: ['clipboard-copy']
	},
      ...
    }
  }
};
@dendyswaran
Copy link

thumbs up for @OG84

for those who r still having issues when using a vanilla svelte + vite 2, you can adjust the vite.config.js as follow

export default defineConfig({ plugins: [svelte()], optimizeDeps: { include: ['clipboard-copy'] } })

@brunnerh
Copy link
Contributor

brunnerh commented Jun 6, 2021

Duplicate of #598

@metonym
Copy link
Collaborator

metonym commented Jul 5, 2021

It is no longer necessary to instruct vite to optimize clipboard-copy as of carbon-components-svelte v0.39.

The clipboard-copy dependency has been removed.

Instead, CodeSnippet and CopyButton use the native, asynchronous Clipboard API to copy text. The functionality is exported as a prop so the user can override the behavior as needed.

Note: the clipboard.writeText API is not supported in IE 11 nor Safari iOS version 13.3 or lower. caniuse estimates that ~91% of global users use a browser compatible with the API.

Overriding default copy behavior

Override the default functionality through the copy prop.

<script>
  import copy from "clipboard-copy";
  import { CopyButton } from "carbon-components-svelte";
</script>

<CopyButton text="hello" copy={text => copy(text)} />

Preventing default copy behavior

Pass a "no-op" empty function to prevent the component from copying text at all.

<script>
  import { CopyButton } from "carbon-components-svelte";
</script>

<CopyButton text="hello" copy={() => {}} />

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

No branches or pull requests

4 participants