Svelte import { x } from ‘https://cdn.jsdelivr.net/npm/x’;

huangapple go评论81阅读模式
英文:

Svelte import { x } from 'https://cdn.jsdelivr.net/npm/x';

问题

So I'm building an App with svelte, and I'm trying to import the transformers.js library

I tried the code import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.3.0';

Yet I receive the error Cannot find module 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.3.0' imported from '/home/projects/story-ai-h9fvbs/src/routes/create/+page.svelte'

The error itself makes sense, as the file wouldn't be there, and I know the CDN link works, so why is svelte looking for it there? How do I fix that?

also, I saw This Example but it uses await import('https://cdn.jsdelivr.net/npm/svelte-qrcode') while I'm trying to get another format.

英文:

So I'm building an App with svelte, and I'm trying to import the transformers.js library

I tried the code import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.3.0';

Yet I receive the error Cannot find module 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.3.0' imported from '/home/projects/story-ai-h9fvbs/src/routes/create/+page.svelte'

The error itself makes sense, as the file wouldn't be there, and I know the CDN link works, so why is svelte looking for it there? How do I fix that?

also, I saw This Example but it uses await import('https://cdn.jsdelivr.net/npm/svelte-qrcode') while I'm trying to get another format.

答案1

得分: 3

这些类型的导入在服务器端渲染期间显然不受支持。您可以在存储库中提出此问题。

我的建议是只在本地安装模块,然后从那里导入。

关闭SSR也可以解决错误,因为导入将在客户端上工作,尽管这会带来其自身的问题。

英文:

These kinds of imports are apparently not supported during server-side rendering. You could open an issue about this in the repository.

My recommendation would be to just install the module locally and import from there.

Turning off SSR would also fix the error as the import would work on the client, though this comes with its own downsides.

huangapple
  • 本文由 发表于 2023年7月17日 10:15:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76701150.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定