我有一个集成了 electron 和 svelte 以及 typescript 支持的设置。当我运行rollup脚本来编译 svelte 应用程序时,出现无法找到模块./App.svelte错误,如下所示。Plugin typescript: @rollup/plugin-typescript TS2307: Cannot find module './App.svelte' or its corresponding type declarations.这是我的package.json配置:{ "name": "tapwire-electron-first", "productName": "tapwire-electron-first", "version": "1.0.0", "description": "My Electron application description", "main": "dist/index.js", "scripts": { "electron-start": "tsc && electron-forge start", "electron-package": "electron-forge package", "electron-make": "electron-forge make", "electron-publish": "electron-forge publish", "electron-lint": "eslint --ext .ts .", "svelte-build": "rollup -c", "svelte-dev": "rollup -c -w", "svelte-start": "sirv public", "svelte-validate": "svelte-check", "start": "run-p svelte-dev electron-start" }, "keywords": [], "author": { "name": "nateshmbhat", }, "license": "MIT", "config": { "forge": { "packagerConfig": {}, "makers": [ { "name": "@electron-forge/maker-squirrel", "config": { "name": "tapwire_electron_first" } }, { "name": "@electron-forge/maker-zip", "platforms": [ "darwin" ] }, { "name": "@electron-forge/maker-deb", "config": {} }, { "name": "@electron-forge/maker-rpm", "config": {} } ] } }, "devDependencies": { "@electron-forge/cli": "^6.0.0-beta.53", "@electron-forge/maker-deb": "^6.0.0-beta.53", "@electron-forge/maker-rpm": "^6.0.0-beta.53", "@electron-forge/maker-squirrel": "^6.0.0-beta.53", "@electron-forge/maker-zip": "^6.0.0-beta.53", "@rollup/plugin-commonjs": "^15.1.0", "@rollup/plugin-node-resolve": "^9.0.0", "@rollup/plugin-typescript": "^6.0.0", "@types/node": "^14.11.2", "@typescript-eslint/eslint-plugin": "^2.34.0", },
4 回答
一只名叫tom的猫
将此 tsconfig 添加为您的基本配置文件
TA贡献1906条经验 获得超3个赞
结果我必须@tsconfig/svelte
先安装为开发依赖项,然后用我的扩展它,tsconfig.json
如下所示:
安装@tsconfig/svelte
npm i --save-dev @tsconfig/svelte
将此 tsconfig 添加为您的基本配置文件tsconfig.json
:
{ "extends": "@tsconfig/svelte/tsconfig.json", }
至尊宝的传说
TA贡献1789条经验 获得超10个赞
我这边的罪魁祸首是陈旧的global.d.ts
。我已经/// <reference types="@sveltejs/kit" />
设置好,但正试图将项目更改为香草 Svelte。将其固定为 have/// <reference types="svelte" />
就可以了。
慕桂英3389331
TA贡献2036条经验 获得超8个赞
这个文件应该可以作为一个基本的 shim:
// svelte-shim.d.ts
declare module "*.svelte" {
import type { ComponentType } from "svelte";
const component: ComponentType;
export default component;
}
这实质上告诉 TypeScript,它不知道如何处理的任何 .svelte 文件都应该作为 Svelte 组件读取。您不会获得他们导出的任何道具或方法,但如果您只需要使用他们的基本ComponentType界面,这应该可以正常工作。
添加回答
举报
0/150
提交
取消