Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nuxt custom plugin exports is not defined

My new Nuxt app is going to be API heavy so I created a new top level folder named api and inside of this folder all of the api routes will be defined but currently there is just users.ts

In api/users.ts:

export default $axios => ({

    create(payload: any) {}

    showAll(): any {
        return $axios.get('...');
    }

}

And then in my plugins folder I created a module export all of the apis named plugins/api.ts:

import users from '../api/users';

export defaut ({ app }, inject) => {

    app.api = { usersAPI: users }

}

And finally in my nuxt.config.ts:

...
plugins: [
    '~/plugins/api'
],
...

But in the browser when I load the page I am getting ReferenceError: exports is not defined

I have a suspicion it might be something to do with Typescript but I have followed the Typescript support guide in the documentation and installed @nuxt/typescript as a dev dependency and ts-node as a normal dependency and changed the file extension of the config file to use .ts.

I have also created a tsconfig.json file that has:

{
    "compilerOptions": {
        "allowSyntheticDefaultImports": true
    }
}
like image 538
Mr.Smithyyy Avatar asked May 10 '19 18:05

Mr.Smithyyy


2 Answers

default is misspelled. It currently says export defaut.

like image 192
CQ Smooth Avatar answered Nov 19 '22 07:11

CQ Smooth


You written export defaut ({ app }, inject) => {

But as CQ said it has to be export default

Consider using some kind of linter like eslint or tslint and also some IDE like vscode.

like image 1
ScreamZ Avatar answered Nov 19 '22 09:11

ScreamZ