找不到模块“./App.svelte”或其对应的类型声明
Posted
技术标签:
【中文标题】找不到模块“./App.svelte”或其对应的类型声明【英文标题】:Cannot find module './App.svelte' or its corresponding type declarations 【发布时间】:2021-01-19 11:45:20 【问题描述】:我有一个将电子与 svelte 以及打字稿支持集成在一起的设置。
当我运行 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",
"@typescript-eslint/parser": "^2.34.0",
"cross-env": "^7.0.2",
"electron": "10.1.3",
"eslint": "^7.10.0",
"eslint-plugin-import": "^2.22.1",
"npm-run-all": "^4.1.5",
"rollup": "^2.28.2",
"rollup-plugin-livereload": "^2.0.0",
"rollup-plugin-svelte": "^6.0.1",
"rollup-plugin-terser": "^7.0.2",
"svelte": "^3.29.0",
"svelte-check": "^1.0.55",
"svelte-preprocess": "^4.3.2",
"typescript": "^4.0.3"
,
"dependencies":
"concurrently": "^5.3.0",
"electron-reload": "^1.5.0",
"electron-squirrel-startup": "^1.0.0",
"sirv-cli": "^1.0.6"
【问题讨论】:
使用经过良好测试的电子和苗条入门包:github.com/nateshmbhat/svelte-electron-ts-starter 见official docs on Svelte with TypeScript 【参考方案1】:在使用 tsc
编译 Typescript 时,我在默认的 react-ts
vite 项目中遇到了同样的问题
我必须删除 tsconfig.json
中的以下行
"skipLibCheck": false,
【讨论】:
【参考方案2】:原来我必须先安装@tsconfig/svelte
作为开发依赖项,然后用我的tsconfig.json
扩展它,如下所示:
安装@tsconfig/svelte
npm i --save-dev @tsconfig/svelte
将此 tsconfig 添加为您的 tsconfig.json
中的基本配置文件:
"extends": "@tsconfig/svelte/tsconfig.json",
【讨论】:
以上是关于找不到模块“./App.svelte”或其对应的类型声明的主要内容,如果未能解决你的问题,请参考以下文章
带有 Yarn、TypeScript 和 React Native 的 Lerna:找不到模块“@project/common”或其对应的类型声明。ts(2307)
React,Typescript - 找不到模块...或其相应的类型声明