Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

258
Visualizações
Importing a JS npm library in Svelte

I don't understand how to import a random npm library in Svelte.

Take the scrapegoat library for example, a library to read CalDAV objects. I created a brand new Svelte project:

$ npx degit sveltejs/template my-svelte-project
$ cd my-svelte-project/
$ npm install
$ npm install -D scrapegoat

Not sure if it should be added to the devDependencies but it doesn't seem to make a lot of difference if it is not. Now, in the src/App.svelte I add this singe line in the existing <script> tag.

import scrapegoat from 'scrapegoat'

Running npm run dev throws the following error:

[!] Error: Unexpected token (Note that you need @rollup/plugin-json to import JSON files)
node_modules/scrapegoat/package.json (2:9)
1: {
2:   "_from": "scrapegoat@^2.0.0",
            ^
3:   "_id": "scrapegoat@2.0.0",
4:   "_inBundle": false,
Error: Unexpected token (Note that you need @rollup/plugin-json to import JSON files)
    at error (node_modules/rollup/dist/shared/rollup.js:158:30)
    at Module.error (node_modules/rollup/dist/shared/rollup.js:12420:16)
    at Module.tryParse (node_modules/rollup/dist/shared/rollup.js:12823:25)
    at Module.setSource (node_modules/rollup/dist/shared/rollup.js:12726:24)
    at ModuleLoader.addModuleSource (node_modules/rollup/dist/shared/rollup.js:22197:20)

This is what I understood from Rich Harris' reply but I am clearly missing something.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The package you’re importing imports its own package.json. Rollup won’t handle JSON imports by default, so you will need to install the json plugin and add it to your Rollup config.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda