N
Nuxtciaddi

How to import functions in a .vue component from a .js file?

import { myfunctions} from "/js/stats.js" doesnt work for me: Error 500 vite_ssr_import_7.default.getData is not a function
P
pyplacca14d ago
You probably don’t have a function with that name And check the path too. You probably wanted to type ”~/js/stats.js” or ”./js/stats.js” instead of ”/js/stats.js”
C
ciaddi14d ago
Hello, there is a function called getData inside my js file: "export const utils = { getData: function () { return "Test" } }". and then import { utils } from "/js/stats.js" but utils.getData() gives me the error "Cannot read properties of undefined (reading 'getData')". Also your suggestions doesnt work "[vite-node] [ERR_LOAD_URL] ~/js/stats.js"
P
pyplacca14d ago
Care to share a screenshot of your directory tree?
C
ciaddi14d ago
No description
P
pyplacca14d ago
I’d recommend you relocate the js folder outside of the public folder. I don’t think nuxt allows you to import from that directory inside your scripts
C
ciaddi14d ago
ohh sure inside assets thx now its working
P
pyplacca14d ago
You can also make use of the root-level utils directory nuxt offers, and keep all your utility functions there. This directory has built-in support for auto imports (if it’s something you prefer)
Want results from more Discord servers?
Add your server
More Posts
skeleton does not work on dynamic routesguys, can anyone help me? the skeleton is appearing on the main page but on the page where the produhow to generate static HTML pages just for some of the routesI'm trying to generate 4 static HTML pages from a huge list of routes that the app has But I only seUDashboardPanel footer (@nuxt/ui-pro)I'm trying to put a footer on the main (`grow` enabled) panel but I can't get the css right. in the useRuntimeConfig() is returning undefined valuesIn my `.env` file I have something like this: ``` NUXT_PUBLIC_LOGIN_DOMAINS="domain1.com,domain2.co@nuxt/eslint autofix?when using `@nuxt/eslint` instead of the old `@nuxtjs/eslint-module` how does one enable autofix? `Check whether any page has fully mounted from the root App.vueSome of my pages have a ```ts definePageMeta({ hideSidebar: true }) ``` which sets the `hideSidebarGetting error "Component is already mounted" when using "useFetch()" and changing route.I am getting the error in my console: ``` [nuxt] [useFetch] Component is already mounted, please uHelp with postinstall: sh: nuxt: not foundHello, I need help with a concern I have regarding the `postinstall` script that runs `nuxt prepare`Types errors in Storybook and tests after upgrade nuxt to 3.11.0Hello there! I upgrade the nuxt version from 3.9.0 to 3.11.0, but now when I run `npm run tsc` I geNuxt eslint module helpI'm joining a new nuxt project that have vue3 eslint plugin, does the Nuxt Eslint Module replace theTailwind CSS errorKeep getting this error in my Nuxt project on saveRouting to another page leads to null parent node errorWhen converting a Vue app to Nuxt and after following directory and layout structures, routing leadsi18n doesn't work with 3.11I already reported a bug for it, just wanted to post for posterity. When using `getRoutseBaseName`,eslint vs typescript 5.45.4.3 is being pulled by nuxt but eslint doesn't like it even if I explictly install the latest `vituseNuxtApp doesn't have my custom pluginsThere are no my custom plugins inside the useNuxtApp hook, they just don't show up.Middleware called 3 times instead of 2 ? (stackblitz reproduction)Can you tell me why my middleware is called 3 times ? https://stackblitz.com/edit/github-3enzca-ixdadd class to default root div __nuxtHi, I'm migrating a VUE 3 SSR project to Nuxt 3 and saw that Nuxt adds a rot div that we don't have Maximum call stack size exceededGetting the below error after updating my nuxt version from ('^3.5.1') to ('^3.11.1). and it will brModule creation questionI'm working on a module and I need to install another module that can import/install other modules oWays to have local middleware inside server/I want to do authentication inside some of protected api routes. normally i have to put the checking