Open sambhav-gore opened 1 year ago
UPDATE
If I build and preview it I do see the PWA is correctly made and I see correct logs in the browser too but my VS code is still complaining about not able to find the module.
Same issue on Webstorm, even after following the Accessing PWA info part.
Same issue here, I tried everything specified in the docs: added types to tsconfig.json
, added /// <reference types="vite-plugin-pwa/client" />
and / or /// <reference types="vite-plugin-pwa/svelte" />
, etc. nothing worked I'm still experiencing the module not found error messages. Though the app works it just can't assign the types. So right now I'm just resorting to // ts-ignore
Also the same errors also pop up in the example project repo
can you try importing the modules (or use the triple slash reference in the corresponding svelte file script)?
// src/app.d.ts
import 'vite-plugin-pwa/info';
import 'vite-plugin-pwa/svelte';
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface Platform {}
}
}
export {};
Still the same
@Naviamold1
Can you check typescript version? I'm using 5.2.2
EDIT: sorry, you're not using TypeScript
ye im also using 5.2.2
Can you check typescript version? I'm using 5.2.2
EDIT: sorry, you're not using TypeScript
I am
the create svelte@latest
for some reason just does <script>
instead of <script lang='ts'>
in the +layout.svelte
even when selecting using typescript option in the installer
I guess SvelteKit should switch to module resolution bundler
, can you edit the .sveltekit/tsconfig.json
file and replace "moduleResolution": "node"
to "moduleResoluton": "bundler"
(will be override once dev server restarted)?
@Naviamold1 can your trying adding a new src/vite-env.d.ts
file removing the imports/references in src/app.d.ts
?
/// <reference types="vite-plugin-pwa/info" />
/// <reference types="vite-plugin-pwa/svelte" />
or (it seems your are using the virtual for VanillaJS)
/// <reference types="vite-plugin-pwa/info" />
/// <reference types="vite-plugin-pwa/vanillajs" />
I'm using Node 18 with these plugins (I use VSCode to test TypeScript only):
@userquin do you have vite-plugin-pwa
declared explicitly in your dependencies in that project?
Aside: I can't test with the example project in this repo because pnpm can't seem to find the package at the root of the monorepo with the workspace protocol
I'm using npm
, this is the package.json
:
{
"name": "sveltekit-latest-example",
"version": "0.0.1",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"run-tsc": "svelte-check --help",
"check": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json --watch"
},
"devDependencies": {
"@fontsource/fira-mono": "^4.5.10",
"@neoconfetti/svelte": "^1.0.0",
"@sveltejs/adapter-auto": "^2.0.0",
"@sveltejs/kit": "^1.20.4",
"@types/cookie": "^0.5.1",
"@vite-pwa/sveltekit": "^0.2.5",
"svelte": "^4.2.0",
"svelte-check": "^3.4.3",
"typescript": "^5.2.2",
"unplugin-icons": "^0.16.6",
"vite": "^4.4.2"
},
"type": "module"
}
Ahh, works for me if I use npm but not with pnpm, probably because of hoisting or whatever it's called.
Also works if I install vite-plugin-pwa directly. Maybe these types could be exposed through a single entrypoint in @vite-pwa/sveltekit?
huh ye with npm its working but not with pnpm
ok, to make it working with pnpm, you need to add 2 entries to .npmrc
, auto-install-peers
and shamefully-hoist=true
:
engine-strict=true
resolution-mode=highest
auto-install-peers=true
shamefully-hoist=true
EDIT: engine-strict
and resolution-mode
added by kit, beware, running pnpm install
will ask you to remove the node_modules
folder
Ok um this solved 3 errors but 1 error still remains
can you try adding the imports in src/app.d.ts
and removing the triple slash references from src/vit-env.d.ts
?
// src/app.d.ts
import 'vite-plugin-pwa/info';
import 'vite-plugin-pwa/vanillajs'; // <== or import 'vite-plugin-pwa/svelte'; if using the virtual module for svelte
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface Platform {}
}
}
export {};
// src/app.d.ts import 'vite-plugin-pwa/info'; import 'vite-plugin-pwa/vanillajs'; // <== or import 'vite-plugin-pwa/svelte'; if using the virtual module for svelte // See https://kit.svelte.dev/docs/types#app // for information about these interfaces declare global { namespace App { // interface Error {} // interface Locals {} // interface PageData {} // interface Platform {} } } export {};
YES this worked now all errors are gone.
The 'import vite-plugin-pwa/svelte'
didnt work but import 'vite-plugin-pwa/vanillajs'
did, even though it's a sveltekit applications.
You're using the virtual module for VanillaJS and so you can use import 'vite-plugin-pwa/vanillajs';
or import 'vite-plugin-pwa/client';
, if you use the virtual for Svelte use import 'vite-plugin-pwa/svelte';
:
import { registerSW } from 'virtual:pwa-register';`
or
import { useRegisterSW } from 'virtual:pwa-register/svelte';`
PWA plugin is fw agnostic, the virtual for Svelte is just a wrapper around the VanillaJS one, exposing info with the reactivity from the framework, in Svelte using Writable stores:
https://github.com/vite-pwa/vite-plugin-pwa/blob/main/src/client/build/svelte.ts
I was following the steps from here - https://vite-pwa-org.netlify.app/frameworks/sveltekit.html
I installed the dependency, added the plugin in the
vite.config.js
and when I am adding the webmanifest link or the register SW code, I am seeing the problem that it is complaining about not able to find the modulevirtual:pwa-info
.Based on what I see in the docs, I have tried adding the
types
in my tsconfig. I also tried adding the references in myapp.d.ts
file (as shown in this example - https://github.com/vite-pwa/sveltekit/blob/main/examples/sveltekit-ts/src/app.d.ts#L1 )But neither have worked for me. VS Code still complains that the module is not found and in the run time It does have any
pwaInfo
.My
+layout.svelte
My
vite.config.ts
My
app.d.ts
:Sveltejs/kit version - 1.7.2 vite-wa/sveltekit version - 0.2.5
What am I doing wrong ? Any help will be appreciated. thanks.