Repository: sveltejs/kit (js)

Issue:
`svelte-kit sync` doesn't run everytime on postinstall for pnpm
### Describe the bug

After following the instruction
```
`svelte-kit sync` now runs on "postinstall" — please remove the "prepare" script from your package.json
```

Sometimes `pnpm run check` fails in a clean workspace (`git clean` / CI).

I believe it has something to do with pnpm's [`side-effects-cache`](https://pnpm.io/npmrc#side-effects-cache). It seems to fixed after disabling `side-effects-cache` in `.npmrc`

### Reproduction

```sh
npm create svelte@latest test-postinstall
cd test-postinstall
pnpm i
rm -rf node_modules .svelte-kit
pnpm i
## no .svelte-kit folder
pnpm run check ## <-- FAIL
```

### Logs

_No response_

### System Info

```shell
npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.64 
    @sveltejs/kit: next => 1.0.0-next.401 
    svelte: ^3.46.0 => 3.49.0 
    vite: ^3.0.0 => 3.0.4
```


### Severity

serious, but I can work around it

### Additional Information

_No response_

Pull request description:
svelte-kit sync before checks
This is #6037, but for `checkjs`. Closes #5779

### Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
- [x] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
- [x] This message body should clearly illustrate what problems it solves.
- [ ] Ideally, include a test that fails without this PR but passes with it.

### Tests
- [x] Run the tests with `pnpm test` and lint the project with `pnpm lint` and `pnpm check`

### Changesets
- [x] If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running `pnpm changeset` and following the prompts. All changesets should be `patch` until SvelteKit 1.0


Patch:
diff --git a/.changeset/two-kings-worry.md b/.changeset/two-kings-worry.md
new file mode 100644
index 000000000..163e091ca
--- /dev/null
+++ b/.changeset/two-kings-worry.md
@@ -0,0 +1,6 @@
+---
+'@sveltejs/kit': patch
+'create-svelte': patch
+---
+
+[breaking] rename `$app/env` to `$app/environment`, to disambiguate with `$env/...`
diff --git a/.changeset/weak-feet-cheer.md b/.changeset/weak-feet-cheer.md
new file mode 100644
index 000000000..8c056bdd4
--- /dev/null
+++ b/.changeset/weak-feet-cheer.md
@@ -0,0 +1,5 @@
+---
+'create-svelte': patch
+---
+
+Add svelte-kit sync to check scripts in checkjs templates
diff --git a/documentation/docs/80-migrating.md b/documentation/docs/80-migrating.md
index ce59f49a1..cde26307d 100644
--- a/documentation/docs/80-migrating.md
+++ b/documentation/docs/80-migrating.md
@@ -162,7 +162,7 @@ declare module 'html-minifier';
 // @filename: index.js
 // ---cut---
 import { minify } from 'html-minifier';
-import { prerendering } from '$app/env';
+import { prerendering } from '$app/environment';
 
 const minification_options = {
 	collapseBooleanAttributes: true,
diff --git a/documentation/faq/80-integrations.md b/documentation/faq/80-integrations.md
index 09b016da2..10991dad5 100644
--- a/documentation/faq/80-integrations.md
+++ b/documentation/faq/80-integrations.md
@@ -48,7 +48,7 @@ If you need access to the `document` or `window` variables or otherwise need cod
 ```js
 /// <reference types="@sveltejs/kit" />
 // ---cut---
-import { browser } from '$app/env';
+import { browser } from '$app/environment';
 
 if (browser) {
 	// client-only code here
diff --git a/packages/create-svelte/shared/+checkjs/package.json b/packages/create-svelte/shared/+checkjs/package.json
index ae2ee38d5..ccd4dd126 100644
--- a/packages/create-svelte/shared/+checkjs/package.json
+++ b/packages/create-svelte/shared/+checkjs/package.json
@@ -1,7 +1,7 @@
 {
 	"scripts": {
-		"check": "svelte-check --tsconfig ./jsconfig.json",
-		"check:watch": "svelte-check --tsconfig ./jsconfig.json --watch"
+		"check": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json",
+		"check:watch": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json --watch"
 	},
 	"devDependencies": {
 		"typescript": "^4.7.4",
diff --git a/packages/create-svelte/templates/default/src/routes/about/+page.ts b/packages/create-svelte/templates/default/src/routes/about/+page.ts
index 3e094ec8e..d08ebec1b 100644
--- a/packages/create-svelte/templates/default/src/routes/about/+page.ts
+++ b/packages/create-svelte/templates/default/src/routes/about/+page.ts
@@ -1,4 +1,4 @@
-import { browser, dev } from '$app/env';
+import { browser, dev } from '$app/environment';
 
 // we don't need any JS on this page, though we'll load
 // it in dev so that we get hot module replacement...
diff --git a/packages/kit/src/core/sync/write_root.js b/packages/kit/src/core/sync/write_root.js
index b8db75fd8..7bc1f7a79 100644
--- a/packages/kit/src/core/sync/write_root.js
+++ b/packages/kit/src/core/sync/write_root.js
@@ -43,7 +43,7 @@ export function write_root(manifest_data, output) {
 			<!-- This file is generated by @sveltejs/kit — do not edit it! -->
 			<script>
 				import { setContext, afterUpdate, onMount } from 'svelte';
-				import { browser } from '$app/env';
+				import { browser } from '$app/environment';
 
 				// stores
 				export let stores;
diff --git a/packages/kit/src/runtime/app/env.js b/packages/kit/src/runtime/app/env.js
index 36ead7671..927c4af84 100644
--- a/packages/kit/src/runtime/app/env.js
+++ b/packages/kit/src/runtime/app/env.js
@@ -1,11 +1,1 @@
-/**
- * @type {import('$app/env').browser}
- */
-export const browser = !import.meta.env.SSR;
-
-/**
- * @type {import('$app/env').dev}
- */
-export const dev = __SVELTEKIT_DEV__;
-
-export { prerendering } from '../env.js';
+throw new Error('$app/env has been renamed to $app/environment');
diff --git a/packages/kit/src/runtime/app/environment.js b/packages/kit/src/runtime/app/environment.js
new file mode 100644
index 000000000..f7b96f8c1
--- /dev/null
+++ b/packages/kit/src/runtime/app/environment.js
@@ -0,0 +1,11 @@
+/**
+ * @type {import('$app/environment').browser}
+ */
+export const browser = !import.meta.env.SSR;
+
+/**
+ * @type {import('$app/environment').dev}
+ */
+export const dev = __SVELTEKIT_DEV__;
+
+export { prerendering } from '../env.js';
diff --git a/packages/kit/src/runtime/app/stores.js b/packages/kit/src/runtime/app/stores.js
index 8f1e21984..0eb99f4df 100644
--- a/packages/kit/src/runtime/app/stores.js
+++ b/packages/kit/src/runtime/app/stores.js
@@ -1,5 +1,5 @@
 import { getContext } from 'svelte';
-import { browser } from './env.js';
+import { browser } from './environment.js';
 import { stores as browser_stores } from '../client/singletons.js';
 
 // TODO remove this (for 1.0? after 1.0?)
diff --git a/packages/kit/types/ambient.d.ts b/packages/kit/types/ambient.d.ts
index f80e5e375..ebde74cb4 100644
--- a/packages/kit/types/ambient.d.ts
+++ b/packages/kit/types/ambient.d.ts
@@ -74,10 +74,10 @@ declare namespace App {
 
 /**
  * ```ts
- * import { browser, dev, prerendering } from '$app/env';
+ * import { browser, dev, prerendering } from '$app/environment';
  * ```
  */
-declare module '$app/env' {
+declare module '$app/environment' {
 	/**
 	 * `true` if the app is running in the browser.
 	 */
diff --git a/sites/kit.svelte.dev/src/lib/search/Search.svelte b/sites/kit.svelte.dev/src/lib/search/Search.svelte
index 07a384352..0b5c47404 100644
--- a/sites/kit.svelte.dev/src/lib/search/Search.svelte
+++ b/sites/kit.svelte.dev/src/lib/search/Search.svelte
@@ -1,5 +1,5 @@
 <script>
-	import { browser } from '$app/env';
+	import { browser } from '$app/environment';
 	import { searching, query } from './stores.js';
 
 	export let q = '';
diff --git a/sites/kit.svelte.dev/src/routes/+error.svelte b/sites/kit.svelte.dev/src/routes/+error.svelte
index 522caa3b0..72f5326cd 100644
--- a/sites/kit.svelte.dev/src/routes/+error.svelte
+++ b/sites/kit.svelte.dev/src/routes/+error.svelte
@@ -1,5 +1,5 @@
 <script>
-	import { dev } from '$app/env';
+	import { dev } from '$app/environment';
 	import { page } from '$app/stores';
 
 	// we don't want to use <svelte:window bind:online> here, because we only care about the online
diff --git a/sites/kit.svelte.dev/src/routes/+layout.svelte b/sites/kit.svelte.dev/src/routes/+layout.svelte
index 5c7871032..075bc84db 100644
--- a/sites/kit.svelte.dev/src/routes/+layout.svelte
+++ b/sites/kit.svelte.dev/src/routes/+layout.svelte
@@ -1,6 +1,6 @@
 <script>
 	import '@sveltejs/site-kit/base.css';
-	import { browser } from '$app/env';
+	import { browser } from '$app/environment';
 	import { page, navigating } from '$app/stores';
 	import { Icon, Icons, Nav, NavItem, PreloadingIndicator, SkipLink } from '@sveltejs/site-kit';
 	import Search from '$lib/search/Search.svelte';


Test patch:
diff --git a/packages/kit/test/apps/amp/src/routes/valid/+page.svelte b/packages/kit/test/apps/amp/src/routes/valid/+page.svelte
index b8a04f492..17bca5973 100644
--- a/packages/kit/test/apps/amp/src/routes/valid/+page.svelte
+++ b/packages/kit/test/apps/amp/src/routes/valid/+page.svelte
@@ -1,5 +1,5 @@
 <script>
-	import { browser, dev } from '$app/env';
+	import { browser, dev } from '$app/environment';
 
 	/** @type {import('./$types').PageData} */
 	export let data;
diff --git a/packages/kit/test/apps/basics/src/routes/actions/form-errors/+page.svelte b/packages/kit/test/apps/basics/src/routes/actions/form-errors/+page.svelte
index 267cd0830..9ca9d4396 100644
--- a/packages/kit/test/apps/basics/src/routes/actions/form-errors/+page.svelte
+++ b/packages/kit/test/apps/basics/src/routes/actions/form-errors/+page.svelte
@@ -1,5 +1,5 @@
 <script>
-	import { browser } from '$app/env';
+	import { browser } from '$app/environment';
 
 	export let errors
 
diff --git a/packages/kit/test/apps/basics/src/routes/errors/clientside/+page.svelte b/packages/kit/test/apps/basics/src/routes/errors/clientside/+page.svelte
index 37f41764d..45c779b91 100644
--- a/packages/kit/test/apps/basics/src/routes/errors/clientside/+page.svelte
+++ b/packages/kit/test/apps/basics/src/routes/errors/clientside/+page.svelte
@@ -1,5 +1,5 @@
 <script>
-	import { browser } from '$app/env';
+	import { browser } from '$app/environment';
 
 	if (browser) {
 		throw new Error('Crashing now');
diff --git a/packages/kit/test/apps/basics/src/routes/errors/load-client/+page.js b/packages/kit/test/apps/basics/src/routes/errors/load-client/+page.js
index 30db34cea..50275c877 100644
--- a/packages/kit/test/apps/basics/src/routes/errors/load-client/+page.js
+++ b/packages/kit/test/apps/basics/src/routes/errors/load-client/+page.js
@@ -1,4 +1,4 @@
-import { browser } from '$app/env';
+import { browser } from '$app/environment';
 
 /** @type {import('@sveltejs/kit').Load} */
 export async function load() {
diff --git a/packages/kit/test/apps/basics/src/routes/errors/module-scope-client/+page.svelte b/packages/kit/test/apps/basics/src/routes/errors/module-scope-client/+page.svelte
index f87c7da0d..26f4a1ab3 100644
--- a/packages/kit/test/apps/basics/src/routes/errors/module-scope-client/+page.svelte
+++ b/packages/kit/test/apps/basics/src/routes/errors/module-scope-client/+page.svelte
@@ -1,5 +1,5 @@
 <script context="module">
-	import { browser } from '$app/env';
+	import { browser } from '$app/environment';
 
 	if (browser) {
 		throw new Error('Crashing now');
diff --git a/packages/kit/test/apps/basics/src/routes/errors/module-scope-server/+page.svelte b/packages/kit/test/apps/basics/src/routes/errors/module-scope-server/+page.svelte
index f499e4693..fb456e19b 100644
--- a/packages/kit/test/apps/basics/src/routes/errors/module-scope-server/+page.svelte
+++ b/packages/kit/test/apps/basics/src/routes/errors/module-scope-server/+page.svelte
@@ -1,5 +1,5 @@
 <script context="module">
-	import { dev } from '$app/env';
+	import { dev } from '$app/environment';
 
 	if (dev) { // can't throw in prod, the app won't start at all
 		throw new Error('Crashing now');
diff --git a/packages/kit/test/apps/basics/src/routes/errors/serverside/+page.svelte b/packages/kit/test/apps/basics/src/routes/errors/serverside/+page.svelte
index c036055e1..cb4f398c1 100644
--- a/packages/kit/test/apps/basics/src/routes/errors/serverside/+page.svelte
+++ b/packages/kit/test/apps/basics/src/routes/errors/serverside/+page.svelte
@@ -1,5 +1,5 @@
 <script>
-	import { dev } from '$app/env';
+	import { dev } from '$app/environment';
 
 	if (dev) { // can't throw in prod, the app won't start at all
 		throw new Error('Crashing now');
diff --git a/packages/kit/test/apps/basics/src/routes/load/+page.js b/packages/kit/test/apps/basics/src/routes/load/+page.js
index 069608981..937a72ade 100644
--- a/packages/kit/test/apps/basics/src/routes/load/+page.js
+++ b/packages/kit/test/apps/basics/src/routes/load/+page.js
@@ -1,4 +1,4 @@
-import { browser } from '$app/env';
+import { browser } from '$app/environment';
 
 /** @type {import('@sveltejs/kit').Load} */
 export function load(pageContext) {
diff --git a/packages/kit/test/apps/basics/src/routes/load/change-detection/one/[x]/+page.js b/packages/kit/test/apps/basics/src/routes/load/change-detection/one/[x]/+page.js
index 30ea122f5..6375027b0 100644
--- a/packages/kit/test/apps/basics/src/routes/load/change-detection/one/[x]/+page.js
+++ b/packages/kit/test/apps/basics/src/routes/load/change-detection/one/[x]/+page.js
@@ -1,4 +1,4 @@
-import { browser } from '$app/env';
+import { browser } from '$app/environment';
 
 let count = 0;
 
diff --git a/packages/kit/test/apps/basics/src/routes/load/fetch-request/+page.js b/packages/kit/test/apps/basics/src/routes/load/fetch-request/+page.js
index 5c13157f0..a3e6165b3 100644
--- a/packages/kit/test/apps/basics/src/routes/load/fetch-request/+page.js
+++ b/packages/kit/test/apps/basics/src/routes/load/fetch-request/+page.js
@@ -1,4 +1,4 @@
-import { browser } from '$app/env';
+import { browser } from '$app/environment';
 
 /** @type {import('@sveltejs/kit').Load} */
 export async function load({ fetch }) {
diff --git a/packages/kit/test/apps/basics/src/routes/redirect-on-load/+page.js b/packages/kit/test/apps/basics/src/routes/redirect-on-load/+page.js
index 5cf9a8a68..be5f4e07f 100644
--- a/packages/kit/test/apps/basics/src/routes/redirect-on-load/+page.js
+++ b/packages/kit/test/apps/basics/src/routes/redirect-on-load/+page.js
@@ -1,5 +1,5 @@
 import { redirect } from '@sveltejs/kit';
-import { browser } from '$app/env';
+import { browser } from '$app/environment';
 
 export async function load() {
 	if (browser) {
diff --git a/packages/kit/test/apps/basics/src/routes/routing/cancellation/a/+page.js b/packages/kit/test/apps/basics/src/routes/routing/cancellation/a/+page.js
index a5091c423..90c242efe 100644
--- a/packages/kit/test/apps/basics/src/routes/routing/cancellation/a/+page.js
+++ b/packages/kit/test/apps/basics/src/routes/routing/cancellation/a/+page.js
@@ -1,4 +1,4 @@
-import { browser } from '$app/env';
+import { browser } from '$app/environment';
 
 /** @type {import('@sveltejs/kit').Load} */
 export async function load() {
diff --git a/packages/kit/test/apps/options/source/components/Message.svelte b/packages/kit/test/apps/options/source/components/Message.svelte
index e38144a08..03aaba873 100644
--- a/packages/kit/test/apps/options/source/components/Message.svelte
+++ b/packages/kit/test/apps/options/source/components/Message.svelte
@@ -1,5 +1,5 @@
 <script>
-	import { browser, dev } from '$app/env';
+	import { browser, dev } from '$app/environment';
 </script>
 
 <p>Hello from the {browser ? 'client' : 'server'} in {dev ? 'dev' : 'prod'} mode!</p>
\ No newline at end of file
diff --git a/packages/kit/test/apps/options/source/pages/mode/+page.svelte b/packages/kit/test/apps/options/source/pages/mode/+page.svelte
index 466630884..6cde263d4 100644
--- a/packages/kit/test/apps/options/source/pages/mode/+page.svelte
+++ b/packages/kit/test/apps/options/source/pages/mode/+page.svelte
@@ -1,5 +1,5 @@
 <script>
-	import { dev } from '$app/env';
+	import { dev } from '$app/environment';
 
 	/** @type {import('./$types').PageData} */
 	export let data;
diff --git a/packages/kit/test/apps/writes/src/routes/double-mount/+page.svelte b/packages/kit/test/apps/writes/src/routes/double-mount/+page.svelte
index 6f94e183b..9fcd170c4 100644
--- a/packages/kit/test/apps/writes/src/routes/double-mount/+page.svelte
+++ b/packages/kit/test/apps/writes/src/routes/double-mount/+page.svelte
@@ -1,5 +1,5 @@
 <script context="module">
-	import { browser } from '$app/env';
+	import { browser } from '$app/environment';
 
 	if (browser) {
 		window.mounted = window.mounted || 0;
diff --git a/packages/kit/test/prerendering/basics/src/hooks.js b/packages/kit/test/prerendering/basics/src/hooks.js
index b8df4f86b..b27a99e8a 100644
--- a/packages/kit/test/prerendering/basics/src/hooks.js
+++ b/packages/kit/test/prerendering/basics/src/hooks.js
@@ -1,4 +1,4 @@
-import { prerendering } from '$app/env';
+import { prerendering } from '$app/environment';
 
 const initial_prerendering = prerendering;