From 97afbde7db0406de2439ce24d99a7564d7e6cac8 Mon Sep 17 00:00:00 2001 From: sapphi-red Date: Sat, 30 Jul 2022 20:52:42 +0900 Subject: [PATCH 1/2] docs: ESM is always strict mode --- docs/guide/troubleshooting.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/guide/troubleshooting.md b/docs/guide/troubleshooting.md index c7e558f0f08192..69bc416375cb49 100644 --- a/docs/guide/troubleshooting.md +++ b/docs/guide/troubleshooting.md @@ -65,3 +65,18 @@ If you are running Vite with WSL2, Vite cannot watch file changes in some condit If HMR is not handled by Vite or a plugin, a full reload will happen. Also if there is a dependency loop, a full reload will happen. To solve this, try removing the loop. + +## Others + +### Syntax Error / Type Error happens + +Vite cannot handle and does not support code that only runs on non-strict mode (sloppy mode). +This is because Vite uses ESM and it is always [strict mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) inside ESM. + +For example, you might see these errors. + +> [ERROR] With statements cannot be used with the "esm" output format due to strict mode + +> TypeError: Cannot create property 'foo' on boolean 'false' + +If these code are used inside dependecies, you could use [`patch-package`](https://github.com/ds300/patch-package) (or [`yarn patch`](https://yarnpkg.com/cli/patch) or [`pnpm patch`](https://pnpm.io/cli/patch)) for an escape hatch. From 53224c3a81bc9dc999080ef9e13a2b3ec6d7310c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Sat, 30 Jul 2022 21:21:23 +0900 Subject: [PATCH 2/2] docs: tweak --- docs/guide/troubleshooting.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/guide/troubleshooting.md b/docs/guide/troubleshooting.md index 69bc416375cb49..1021d9e41f04b1 100644 --- a/docs/guide/troubleshooting.md +++ b/docs/guide/troubleshooting.md @@ -70,8 +70,7 @@ Also if there is a dependency loop, a full reload will happen. To solve this, tr ### Syntax Error / Type Error happens -Vite cannot handle and does not support code that only runs on non-strict mode (sloppy mode). -This is because Vite uses ESM and it is always [strict mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) inside ESM. +Vite cannot handle and does not support code that only runs on non-strict mode (sloppy mode). This is because Vite uses ESM and it is always [strict mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) inside ESM. For example, you might see these errors.