Issues with errors stating 'Property does not exist' are appearing in the terminal but not in the Chrome console when using Nuxt/Prismic

I am in the process of developing a product catalogue website using Nuxt and Prismic. Currently, my focus is on fetching navigation sections (product categories) from Prismic to display them in a sidebar.

Although everything appears to be functioning correctly (content loads and displays as intended), I am encountering the following errors in the terminal window while running npm run dev:

ERROR ERROR in components/Sidebar.vue:29:14
14:35:49 TS2339: Property 'fetch' does not exist on type '{ data(): { heading: string; sections: never[]; }; created(): void; methods: { fetch(): Promise; }; }'. 27 | }, 28 | created() { 29 | this.fetch() | ^^^^^ 30 | }, 31 | methods: { 32 | async fetch() {

ERROR in components/Sidebar.vue:35:20 TS2339: Property '$prismic' does not exist on type '{ fetch(): Promise; }'. 33 | const that = this; 34 | // TODO : Move Prismic call to actions.ts - this.$store.dispatch('fetchSections') 35 | await this.$prismic.api | ^^^^^^^^ 36 | .getByUID('navigation', 'categories') 37 | .then(function(document) { 38 | console.log(document)

ERROR in components/Sidebar.vue:37:24 TS7006: Parameter 'document' implicitly has an 'any' type. 35 | await this.$prismic.api 36 | .getByUID('navigation', 'categories') 37 | .then(function(document) { | ^^^^^^^^ 38 | console.log(document) 39 | that.heading = document.data.doc_name[0].text 40 | that.sections = document.data.nav

ERROR in components/Sidebar.vue:39:18 TS2339: Property 'heading' does not exist on type '{ fetch(): Promise; }'. 37 | .then(function(document) { 38 | console.log(document) 39 | that.heading = document.data.doc_name[0].text | ^^^^^^^ 40 | that.sections = document.data.nav 41 | }) 42 | }

ERROR in components/Sidebar.vue:40:18 TS2339: Property 'sections' does not exist on type '{ fetch(): Promise; }'. 38 | console.log(document) 39 | that.heading = document.data.doc_name[0].text 40 | that.sections = document.data.nav | ^^^^^^^^ 41 | }) 42 | } 43 | }

ERROR in components/SidebarSection.vue:43:26 TS2339: Property 'section' does not exist on type '{ name: string; props: { section: { type: ObjectConstructor; required: boolean; }; isCollapsed: { type: BooleanConstructor; }; }; mounted(): void; }'. 41 | }, 42 | mounted() { 43 | console.log(this.section.items[0].sub_nav_link_label[0].text) | ^^^^^^^ 44 | } 45 | } 46 |

Despite these errors in the terminal, there are no visible issues in the Chrome console output.

Below is the code snippet for export default within Sidebar.vue:

export default {
    data() {
        return {
            heading: "",
            sections: []
        }
    },
    created() {
        this.fetch()
    },
    methods: {
        async fetch() {
            const that = this;
            // TODO : Move Prismic call to actions.ts - this.$store.dispatch('fetchSections')
            await this.$prismic.api
            .getByUID('navigation', 'categories')
            .then(function(document) {
                console.log(document)
                that.heading = document.data.doc_name[0].text
                that.sections = document.data.nav
            })
        }
    }
}

The only potential issue I can think of is related to the declaration file used to provide TypeScript type information about the Prismic API. This file is located in a types folder and referenced in:

"files": [
  "prismic.d.ts"
]

within tsconfig.json.

If anyone has any suggestions, they would be greatly appreciated.

EDIT:

Upon running npm run dev from VSCode instead of a separate terminal window, errors throughout the project arise whenever a Prismic type is utilized. The following error message stands out:

import { PrismicAPI } from '~/types/prismic'

Cannot find module '~/types/prismic' or its corresponding type declarations.

Answer №1

It appears that the issue lies in how prismic.d.ts is being included in the tsconfig.json file. Have you tried using the include option instead of files, and specifying the absolute path for prismic.d.ts like so:

{
  "include": ["types/prismic.d.ts"]
}

For more information, you can refer to this link: https://www.typescriptlang.org/tsconfig#include

Answer №2

Upon reviewing your code, I noticed the following:

this.heading = document.data.doc_name[0].text
this.sections = document.data.nav

The correct syntax should be:

this.heading =document.data.doc_name[0].text
this.sections = document.data.nav

This will enable you to access it from the reactive data.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Emptying the form input fields

[![output image][1]][1] I am facing an issue on my webpage where input fields are not getting cleared even after clicking the submit button. I have written a code to read data from a JSON file, display it, take input from users, and display it along with ...

Adding a class-matched element with a corresponding ID

Despite finding similar questions, I am still unable to achieve the desired outcome. Here is a list: <ul> <li class="class1"></li> <li class="class2"></li> <li class="class3"></li> <li class="class4"&g ...

Excessive messages are being sent to the child process from the nodejs/electron stream

When trying to send messages from an Electron frontend to a C++ child process via stdin upon button press, I encountered an issue where multiple identical sends were triggered with each click. What is the recommended approach to prevent redundant messages ...

Synchronizing data between parent and child components using two-way binding with emit in Vue 3 using TypeScript

Within my code, there is a child component: <template> <label :class="className + ' ctrl'"> <span><LocCtrl :page="pageName" :locKey="labelLoc" /></span> <input type=&q ...

How can I access the Vue instance in Vuepress2 in order to utilize external Vue plugins?

Trying to implement v-wave within VuePress 2 (the updated version powered by Vue 3). Followed the documentation and attempted to integrate v-wave as a local plugin in VuePress 2. .vuepress/config.js const vwave = require('path/to/v-wave.js'); ...

Retrieve the quantity of files in a specific directory by implementing AJAX within a chrome extension

I need assistance with obtaining the count of images in a specific directory using JS and AJAX within my chrome extension. My current code is included below, but it does not seem to be functioning as expected since the alert is not displaying. main.js .. ...

Incorporating a stationary navigation bar alongside a parallax scrolling layout

After spending the entire night trying to figure this out, I have had zero success so far. I decided to tackle this issue with javascript since my attempts with CSS have been completely fruitless. This is a demonstration of the parallax scrolling webpage. ...

The module '*/node_modules/ngx-echarts/ngx-echarts' does not have the exported member 'Ngx Echarts Service' available for use

Initially, my Angular 6 project was functioning perfectly with all the packages in working order. However, upon attempting to upgrade it to Angular 8, I encountered the following error message when running ng serve: The module '"*/node_modules/ngx ...

Using Vue.js with typeahead feature: the missing link

I'm currently working on creating a form with autocomplete functionality. The goal is to have a user input part of a name, which will then trigger suggestions from our database. Upon selecting a suggestion, I want the entire form to be populated with ...

Navigating poorly structured HTML tables using jQuery code loops

I am currently working on a project that involves an HTML table generated by my client, and it seems like we are both in agreement not to change how the code is generated at this time. <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0> <TR HEIG ...

Is there a way to utilize jQuery's load function to fetch just a single element rather than the entire webpage?

I am looking to make a slight modification to the function so that it only loads the content of the colTwo div from the selected link on the menu, instead of loading the entire page. After checking out the code snippet on the jQuery website: $('#resu ...

Is it possible that the method of wrapping options using an array is not functioning correctly in the quiz app being managed in React?

I need your help in figuring out where I've made a mistake. The following line is causing an error: const choices = Array.forms(document.querySelectorAll('.choice')); console.log(choices); ...

Navigating with Angular and Node: Maximizing the Potential

Currently, I am delving into the world of Node and Angular. As a part of my learning journey, I am in the process of setting up a basic application with three pages. To guide me through this, I have been referring to the documentation provided at: enter li ...

Discovering visible ID numbers on the screen

My content includes the following: <div id="sContainer"> <div class="message0" id="l0">Initial Content 111</div> <div class="message1" id="l1">Initial Content 222</div> <div class="message2" id="l2">Initial ...

Cost-Effective Method for Refining Search Results of an Item

I am working with a JSON file containing movie data and I'm looking to extract only the top ten highest scoring movies: Here is a snippet of the data: { "movies" : { "eraserhead" : { "full_title" : "Eraserhead", ...

Tips for evaluating the outputs of two computed properties in Vue.js

In our application, users can apply to events and we also have blog posts about various events. We want to display all the blog posts related to events that a user has applied to. Each post is associated with an eventId and each application object contain ...

The information transmitted from the Laravel controller is not syncing with the Vue variable as expected

I've been working on a web app with a dashboard using Laravel and Vue. While passing data from the controller to the Vue file, the data is received correctly. However, when I try to set it to a Vue variable, the value does not update in the variable. ...

Conceal the axios request and the express routes from being visible in the browser's network

Currently, I have a Nuxt application utilizing an Express server for routes. When I make API calls for login or other functionalities, I notice that the calls are visible in the network tab and the APIs are exposed. This means that if someone were to atte ...

What is the method for consistently rotating the object regardless of the camera's orientation?

I am trying to rotate an object along the world axis while considering the direction of the camera, so that the rotation remains consistent even when the camera changes direction. The current code allows me to rotate a sphere along the world axis. However ...

Capture the incoming path and direct it back after the user logs in

I'm currently facing a challenge with my app that has a login feature and a dashboard with threads. Each thread has its own unique URL address. The issue arises when I want to share the thread URL with someone who is not logged in, as they would need ...