I have a Vue view, somethink like:
<script setup lang="ts">
import { firstItem } from "@/path/to/my/file";
onMounted(async () => {
let f1 = getFirstItem();
let f2 = getSecondItem();
});
As you can see, there is an Import for firstItem
, but I forgot to add an import for secondItem
.
My issue - Why such a code is passing npm run serve
successfully? In fact, the website does not work (as expeted).
How can I make npm run serve
to fail instead of this confusing scenario that I was sure everything is OK with my code, and was not aware to this error?
By The Way, npm run lint
DO show this error, but I do not remember to run npm run lint
bfore every npm run serve
CodePudding user response:
It is a runtime error, not a compile time error. If you run a type checker before you run npm run serve
, the command will fail.
You can also change your typescript
config settings to report an error.
Somewhere in your typescript settings, you are allowing undeclared global functions, or have disabled the type checking.
Sometimes this happens when the global
object is overriden as type any
.
CodePudding user response:
I sloved the issue by editing package.json file, and adding lint
call on each serve
:
"scripts": {
"serve": "vue-cli-service lint && vue-cli-service serve", ...
This solution is based on https://stackoverflow.com/a/58070493/5699936