-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with Nuxt3: Unexpected token 'export' #333
Comments
@lukaszflorczak Please note that it might work only on 'client' side, it might throw an error on 'server' therefore SSR might not fully work. // tsconfig.json
{
"extends": "./.nuxt/tsconfig.json",
"paths": {
"font-awesome": "./node_modules/@fortawesome/fontawesome-svg-core"
}
} // nuxt.config.ts
// removed from css/plugins sections
...
alias: {
'font-awesome': resolve(__dirname, './node_modules/@fortawesome/fontawesome-svg-core')
},
...
purgeCSS: {
whitelistPatterns: [/svg.*/, /fa.*/]
}, // app.vue
...
<script lang="ts" setup>
import 'font-awesome/styles.css'
import './assets/css/tailwind.css'
</script> // plugins/fontawesome.client.js
import { defineNuxtPlugin } from '#app'
import { library, config } from '@fortawesome/fontawesome-svg-core'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import { fas } from '@fortawesome/free-solid-svg-icons'
export default defineNuxtPlugin(nuxtApp => {
config.autoAddCss = false;
library.add(fas);
nuxtApp.vueApp.component('font-awesome-icon', FontAwesomeIcon);
}) |
I tried it today again, with My code/implementation looks like this – maybe it'll be useful for someone: // nuxt.config.ts
import { defineNuxtConfig } from 'nuxt3'
export default defineNuxtConfig({
css: [
'@fortawesome/fontawesome-svg-core/styles.css'
]
}) // plugins/icons.js
import { defineNuxtPlugin } from '#app'
import { config } from '@fortawesome/fontawesome-svg-core'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
config.autoAddCss = false
export default defineNuxtPlugin(nuxtApp => {
nuxtApp.vueApp.component('fa-icon', FontAwesomeIcon)
}) // composables/icons.js
import { library } from '@fortawesome/fontawesome-svg-core'
export const useIcons = icons => {
for (const [key, value] of Object.entries(icons)) {
if (/^fa/.test(key)) library.add(value)
}
} <!-- In component -->
<template>
<fa-icon :icon="['fas', 'heart']"/>
</template>
<script setup>
import { faHeart } from '@fortawesome/pro-solid-svg-icons'
useIcons({ faHeart })
</script> |
@lukaszflorczak thank you. It seems to be working now 🎉 |
@mateuszgiza and @lukaszflorczak is-it still working for you? I have a 500 error:
With
|
I switched to your versions and it's now working!
|
Yep, |
Is anyone facing the same problem with nuxt-bridge? I'm having the same problem. I created a minimal reproduction here #344 "@fortawesome/fontawesome-svg-core": "^1.3.0",
"@fortawesome/free-solid-svg-icons": "^6.0.0",
"@fortawesome/vue-fontawesome": "^2.0.6", |
Describe the bug
The vue-fontawesome (
3.0.0-5
) doesn't work with Nuxt3 (3.0.0-27244261.c49f9ca
, the same on earlier releases too).Reproducible test case
Clone and run project (branch
test/fontawesome
): https://github.com/lukaszflorczak/nuxt3-demo/tree/test/fontawesomeVisit
http://localhost:3000
The text was updated successfully, but these errors were encountered: