英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论