question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript: Cannot find module '$app/env' or its corresponding type declarations

See original GitHub issue

Describe the bug Typescript can’t resolve anything in $app (env, stores, etc).

To Reproduce Happening with latest create-svelte.

Looks like this can be fixed by editing global.d.ts to include:

// / <reference types="svelte" />

This was previously in the template and was removed without comment, so I’m not sure whether there are unintended consequences to adding it back.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ignatiusmbcommented, Oct 15, 2021

You shouldn’t need to reference anything inside node_modules directly, I took a quick look of the repo and saw you have an invalid global.d.ts containing these lines

declare module '**/*.svelte';
/// <reference types="@sveltejs/kit" />

Triple-slash directives are only valid at the top of their containing file. https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html

Please make sure to always test these bugs with the latest skeleton starter, we should only need this line for everything to work out-of-the-box

https://github.com/sveltejs/kit/blob/7fab7f67a4643715586693cf01fd4d43f54671d0/packages/create-svelte/templates/skeleton/src/global.d.ts#L1

0reactions
sorenabedicommented, Oct 14, 2021

Describe the bug Typescript can’t resolve anything in $app (env, stores, etc).

I am having a similar problem with $app/ etc. build and dev scripts are not affected but svelte check fails …

My workaround for $app/* path (svelte-check and IDE hits)

add ./node_modules/@sveltejs/kit/types/ambient-modules.d.ts to the include array in tsconfig.json e.g:

{
	"compilerOptions": {
		//compilerOptions ...
	},
	"include": [
		"./node_modules/@sveltejs/kit/types/ambient-modules.d.ts",
		"src/**/*.d.ts",
		"src/**/*.js",
		"src/**/*.ts",
		"src/**/*.svelte"
	]
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot find module '@env' or its corresponding type ...
It works but I get a TypeScript error. This is where I set the moduleName: ['module:react-native-dotenv', { ...
Read more >
cannot find module or its corresponding type declarations file
On building my project, I was getting this error (similarly, regarding an import of a Svelte component in a .ts file):. (!) Plugin...
Read more >
Cannot find module '$lib/...' or '$app/...' from language server ...
These throw a diagnostic such as Cannot find module '$lib/Counter.svelte' or its corresponding type declarations and jump to definition does ...
Read more >
[Solved]-typescript can't find module less-Reactjs
Just create a new declaration file ( externals.d.ts ) with declare module '*.less' . Edit If you are using css-modules, you can define...
Read more >
Using React with TypeScript - Mattermost
Learn how to create a new TypeScript app with create-react-app and convert an ... TypeScript problems like “Missing Type Declarations”.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found