shiki icon indicating copy to clipboard operation
shiki copied to clipboard

[Shiki] no CDN provider found

Open jiankafei opened this issue 3 years ago • 12 comments

code

import * as shiki from 'shiki';

const html = ref('');
shiki
  .getHighlighter({
    theme: props.theme,
  })
  .then((highlighter) => {
    html.value = highlighter.codeToHtml(props.content, props.lang);
  })
  .catch(console.warn);

result

[Shiki] no CDN provider found, use `setCDN()` to specify the CDN for loading the resources before calling `getHighlighter()`

jiankafei avatar Sep 01 '21 07:09 jiankafei

Can you say what you did about the error message?

orta avatar Sep 02 '21 15:09 orta

@orta Can we load all resources manually? I don't want to provide static resource path but bundled by vite/webpack.

JounQin avatar Sep 03 '21 15:09 JounQin

When using vite/webpack, there is a hint of no CDN provider found, but npm has already downloaded all themes and languages files, so setting CDN paths should only be an optional configuration?

songhn233 avatar Sep 07 '21 07:09 songhn233

cc @octref

JounQin avatar Sep 18 '21 07:09 JounQin

Please provide a minimal, reproducible example. Link to a repo would be great.

octref avatar Sep 22 '21 19:09 octref

@octref @orta https://codesandbox.io/s/beautiful-swirles-i6fr4

jiankafei avatar Sep 23 '21 02:09 jiankafei

@jiankafei Your example is showing this for error me: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 3c 21 44 4f @+0

octref avatar Dec 23 '21 18:12 octref

+1 for this, CDN feature should be optional in my opinion. especially for desktop apps created with electron, it's not feasible to connect CDN everytime.

for now using

setCDN("/node_modules/shiki/");

with vite worked for me, since vite serves the root directory. but this is temporary and will only work with vite-like bundlers AND in dev mode. in prod you will manually (somehow) have to copy shiki/dist to your dist.

Sparkenstein avatar Mar 31 '22 10:03 Sparkenstein

Agree with @Sparkenstein. For now, as is written in this file, we can load assets by setCDN('https://unpkg.com/shiki/') manually. But it's a little bit confusing, why not just consider node_modules/shiki as a default assets folder 👻(or maybe set a default CDN)

tkzt avatar Apr 23 '22 15:04 tkzt

请提供一个最小的、可重现的例子。链接到回购会很棒。

https://stackblitz.com/edit/vitejs-vite-gqv1wz?file=package.json,src%2Fcomponents%2FHelloWorld.vue,index.html&terminal=dev

https://github.com/shikijs/shiki/issues/346#issuecomment-1229402139

alamhubb avatar Aug 28 '22 11:08 alamhubb

@jiankafei你的例子显示了这个错误我:WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 3c 21 44 4f @+0

image

alamhubb avatar Aug 28 '22 11:08 alamhubb

https://github.com/shikijs/shiki/issues/246

alamhubb avatar Aug 28 '22 11:08 alamhubb

If you are using vite, you can serve shiki assets with https://github.com/sapphi-red/vite-plugin-static-copy to make them both available in dev mode and production.

// vite.config.*
import { viteStaticCopy } from 'vite-plugin-static-copy'

export default {
  plugins: [
    viteStaticCopy({
      targets: [
        {
          src: 'node_modules/shiki',
          dest: '.'
        }
      ]
    })
  ]
}

Set CDN to the assets served by yourself before get the Highlighter:

setCDN('/shiki/')

kingyue737 avatar Nov 06 '22 09:11 kingyue737