Default exports are not supported in TypeScript

I'm encountering issues with my Laravel + Vite + Vue 3 project. I followed the installation instructions in the documentation and everything works fine when the project is separated from Laravel and Vite. However, I'm facing a problem where TypeScript doesn't recognize the export default, resulting in an error message like this:

MainLayout.vue:42 
        
       Uncaught SyntaxError: The requested module '/resources/scripts/composable/Auth.js' does not provide an export named 'default' (at MainLayout.vue:42:1)

Even though the Auth.ts file exports a function as shown below:

export default function useAuth(){
    return {
    CurrentUserToken: 'test';
  };
}

This is how I've tried to call the function in some files:

import useAuth() from './Auth';

const { CurrentUserToken } = useAuth();


return CurrentUserToken;

I'm puzzled as to why it's unable to recognize this named function. Any insights on how to resolve this issue?

Answer №1

To export the function, follow these steps:

export function useAuth() {
    return {
    CurrentUserToken: 'test';
  };
}

Next, import the function:

import { useAuth } from './Auth';

Now, you can execute the function by calling:

useAuth();

Alternatively, if you prefer to export it as default:

export default function() {
    return {
     CurrentUserToken: 'test';
  };
}

For importing the default function, use the following syntax:

import useAuth from './Auth';

Finally, execute the function like this:

useAuth();

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

Tips for customizing MUI PaperProps using styled components

I am trying to customize the width of the menu using styled components in MUI. Initially, I attempted the following: const StyledMenu = styled(Menu)` && { width: 100%; } `; However, this did not have any effect. After further research, I ...

Failed submission: XMLHttpRequest and FormData not processing data correctly

I'm attempting to use AJAX to submit a form using the post method along with a FormData object. Here's a simplified version of the JavaScript code: var form=…; // form element var url=…; // action form['update'].onclick=function ...

Tips for resolving problems with vue-transitions not being activated or triggered by methods

Currently, I am engrossed in a study project centered around vue-cli. It may seem fairly straightforward at first glance, but I am eager to implement some of the new concepts I have been learning. Within my project, I have a header featuring two distinct ...

Navigating the world of gtag and google_tag_manager: untangling

Tracking custom events in my react application using Google Analytics has been successful. Initially, I followed a helpful document recommending the use of the gtag method over the ga method for logging calls. The implementation through Google Tag Manager ...

Struggling to compile SASS in VueJS with WebpackSimple?

I recently set up a fresh installation of VueJs using webpack simple and encountered an issue with configuring SASS to CSS conversion. The documentation states that it supports SCSS, but I need assistance in setting up SASS specifically with the lang="sass ...

Why is it that the edit or delete button is not functioning when I attempt to click on the next page?

Having an issue with my script. It works fine for editing and deleting on the first page, but when I navigate to the next page, those functionalities stop working. Can anyone help me troubleshoot this problem? <script> $(function(){ $(&ap ...

vue-router: display distinct views for the same route depending on the specified condition

We are exploring options to dynamically display different views based on the authentication status of a user, leveraging vue-router I am considering two potential approaches, although I am currently unsure of how to successfully implement either: Utilize ...

Issue encountered when summing numbers: There appears to be a continuous loop updating within a component's rendering function

Let's say I have a variable initialized as 0 and a method that increments this variable... However, when I try to use them, an error message is displayed: [Vue warn]: You may have an infinite update loop in a component render function. Here is the ...

Retrieve HTML content from a JSON object and render it on a web page

I am facing a challenge with decoding html that is in json format. I'm struggling to figure out how to retrieve my html and display it on a page. It seems like json_decode isn't the solution. Can anyone help me with this issue? Appreciate any as ...

What is the proper way to specify a file destination in React?

After reading this article on downloading objects from GCP Cloud storage bucket, I'm curious about setting the file destination dynamically in React. Is there a way to achieve this? The article can be found at: https://cloud.google.com/storage/docs/do ...

Ways to eliminate duplicate objects from an array using Angular 6

I'm having trouble removing duplicate value objects in an array and it's not working as expected. I believe the duplicate function is functioning correctly, but the changes are not being reflected in the li list. Can you pinpoint where I need to ...

ReactJS form submissions failing to detect empty input values

My goal is to use react to console.log the input value. Below is the code I've created: import React from 'react'; import ReactDOM from 'react-dom'; class App extends React.Component{ constructor() { super(); this.proce ...

Transfer text between Angular components

Here is the landing-HTML page that I have: <div class="container"> <div> <mat-radio-group class="selected-type" [(ngModel)]="selectedType" (change)="radioChange()"> <p class="question">Which movie report would you like ...

Guide to incorporating trading-vue-js into a Vue CLI project

Recently, I decided to explore the functionality of trading-vue-js and found it quite interesting. I managed to successfully run the test examples for trading-vue-js without any issues. The steps I took were as follows: nmp install trading-vue-js I then ...

Having trouble populating the input text field with the selected value from a dropdown using JavaScript

I have implemented a JavaScript function to retrieve the id of a dropdown select with id='odrid'. The script looks like this: $('#odrid').change(function(){ $.getJSON( 'fetch.php', 'odrid='+$(&ap ...

Is there a way to loop through objects in Angular 2

I am working with an Array of Objects named comments, and my goal is to select only the ones that have a specific post id and copy them to another array of objects. The issue I am facing is finding a way to duplicate the object once it has been identified. ...

What is the best way to dynamically populate a table with JSON data that is received from an API response?

Currently, I have a table that contains the FORM element: <table id="example" class="sortable"> <caption><h3><strong>Product inventory list</strong></h3></caption> <thead> <tr ...

Developing a vue.js component library without the need for constant rebuilding after every edit

Introduction: I have created two projects using vue-cli ~4.2.0: parent-app - the main project dummylib - a library that is imported by parent-app. It contains several .vue components. Currently, parent-app functions well in dev mode with dummylib being ...

Is it true that DOM objects in JavaScript are considered objects?

I've been searching for an official answer to this question, but it seems there is some confusion. Some people consider DOM objects to be JS objects, while others argue that they are different entities. What is the correct answer? If you search on Sta ...

Struggling to update the position of an array and dynamically show its contents using Angular

I am working with an Array of Objects, each containing an Array of strings. Utilizing ng-repeat to display all the strings, I have a button to switch to the next set of strings by changing the selected object in the outermost array. Below is the code snipp ...