Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Svelte (rollup) - Error: Unexpected token (Note that you need @rollup/plugin-json to import JSON files)

Tags:

rollup

svelte

I am doing nothing to trigger this error. The app works fine one second, and doesn't the next.

Why is this happening? It is not due to the missing @rollup/plugin-json plugin because it worked previously without it.

Error

https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency
path (imported by  path?commonjs-external)
http (imported by  http?commonjs-external)
net (imported by  net?commonjs-external)
url (imported by  url?commonjs-external)
[!] Error: Unexpected token (Note that you need @rollup/plugin-json to import JSON files)
node_modules/mime-db/db.json (2:40)
1: {
2:   "application/1d-interleaved-parityfec": {
                                           ^
3:     "source": "iana"
4:   },
Error: Unexpected token (Note that you need @rollup/plugin-json to import JSON files)
    at error (/mnt/c/ivan/dev/lab/atlas-biotek/node_modules/rollup/dist/shared/rollup.js:5265:30)
    at Module.error (/mnt/c/ivan/dev/lab/atlas-biotek/node_modules/rollup/dist/shared/rollup.js:9835:16)
    at tryParse (/mnt/c/ivan/dev/lab/atlas-biotek/node_modules/rollup/dist/shared/rollup.js:9716:23)
    at Module.setSource (/mnt/c/ivan/dev/lab/atlas-biotek/node_modules/rollup/dist/shared/rollup.js:10142:19)
    at ModuleLoader.addModuleSource (/mnt/c/ivan/dev/lab/atlas-biotek/node_modules/rollup/dist/shared/rollup.js:18312:20)

Adding the plugin

npm i @rollup/plugin-json --save-dev

rollup.js.config

import json from "@rollup/plugin-json";

export default {
    plugins: [
        commonjs(),
        json(),      // <---- put after commonjs
    ]
}

Client error

Uncaught ReferenceError: require$$0$1 is not defined
    at main.js:5
(anonymous) @ main.js:5

UNCAUGHT

like image 813
Ivan Avatar asked Dec 02 '20 13:12

Ivan


1 Answers

The problem was that I was importing a node module in the client due to autocomplete.

import { is } from "express/lib/request";
like image 95
Ivan Avatar answered Sep 21 '22 12:09

Ivan