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
}
}
default is misspelled. It currently says export defaut
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With