Svelte 应用的“导入类型 { 用户 }”中的解析错误

ParserError from `import type { User }` for Svelte app

提问人:flyingfishcattle 提问时间:5/21/2023 更新时间:5/21/2023 访问量:35

问:

尝试通过命令启动 Svelte 应用程序时遇到以下错误:ParseError: Unexpected tokennpm run dev

$ npm run dev 

> [email protected] dev
> rollup -c -w

rollup v3.22.0
bundles src/main.js → public/build/bundle.js...
[!] (plugin svelte) ParseError: Unexpected token
src/App.svelte
4:     import { supabase } from "$lib/db";
5:     import Auth from "$lib/Auth.svelte";
6:     import type { User } from "@supabase/supabase-js";
                   ^
7:     import Home from "$lib/Home.svelte";

这是我正在使用的文件:package.json

 {
  "name": "svelte-app",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "build": "rollup -c",
    "dev": "rollup -c -w",
    "start": "sirv public --no-clear"
  },
  "devDependencies": {
    "@rollup/plugin-commonjs": "^24.0.0",
    "@rollup/plugin-node-resolve": "^15.0.0",
    "@rollup/plugin-terser": "^0.4.0",
    "@tsconfig/svelte": "^4.0.1",
    "concurrently": "^8.0.1",
    "rollup": "^3.15.0",
    "rollup-plugin-css-only": "^4.3.0",
    "rollup-plugin-livereload": "^2.0.0",
    "rollup-plugin-svelte": "^7.1.2",
    "svelte": "^3.59.1",
    "svelte-check": "^3.3.2",
    "svelte-hcaptcha": "^0.1.1",
    "svelte-preprocess": "^5.0.3",
    "tailwindcss": "^3.3.2",
    "tslib": "^2.5.2",
    "typescript": "^5.0.4",
    "vite": "^4.3.8"
  },
  "dependencies": {
    "@supabase/supabase-js": "^2.22.0",
    "sirv-cli": "^2.0.0"
  }
}

请注意,我已经找到了问题的根本原因并解决了此错误。

我将在下面发布答案,以防它也能帮助遇到类似问题的其他人。

tailwind-css svelte rollup 解析错误

评论


答:

0赞 flyingfishcattle 5/21/2023 #1

问题是我在应该使用 .rolluptailwindcss

解决方法是更改文件中的命令以反映使用需求,如下所示:scriptspackage.jsontailwindcss

// Package.json file
...
  "scripts": {
    "dev": "concurrently \"npm run dev:css\" \"vite\"",
    "dev:css": "tailwindcss -w -i ./src/tailwind.css -o src/assets/app.css",
    "build": "npm run build:css && vite build",
    "build:css": "tailwindcss -m -i ./src/tailwind.css -o src/app.css",
    "preview": "vite preview",
    "check": "svelte-check --tsconfig ./tsconfig.json"
  },
...