Baroshem / nuxt-security

🛡 Automatically configure your app to follow OWASP security patterns and principles by using HTTP Headers and Middleware
https://nuxt-security.vercel.app/
MIT License
739 stars 56 forks source link

Adding package leads to build errors Code Unable to Build - Nuxt Build Error: [vite:build-import-analysis] Failed to parse source for import analysis because the content contains invalid JS syntax. Install @vitejs/plugin-vue to handle .vue files #390

Closed nosizejosh closed 2 months ago

nosizejosh commented 3 months ago

Adding this package to my code leads to errors and prevents build. more on this error on this nuxt issue here https://github.com/nuxt/nuxt/issues/26011

Version


vejja commented 3 months ago

Hi @nosizejosh

According to your original bug report, your file D:/proj/components/details/Index.vue:205:64 indeed contains invalid javascript in the unMounted hook It could potentially be related to removeLoggers, would you be ok to share your original code in the unMounted hook? It looks like vite transformed your original code.

nosizejosh commented 3 months ago

hello @vejja

let cardServicesSubscription;
onMounted(async () => {
    // fetching here removes delay and showing of empty content
    const { data: card, error } = await fetchFullCard(selectedPipelineListCard.value.id, selectedPipelineList.value.id, getTenantProfile().id)
    if (card) {
        selectedPipelineListCard.value = card // set store selected card to the fresh full card
        loading.value = false
    }
    if (error) {
        console.log("🚀 ~ error:", error)
        loading.value = false // end loading
        showCardDetailsModal.value = false // hide slide over
    }
    cardServicesSubscription = cardServiceRealtimeSubscription(boardStore)
    console.log("🚀 ~ onMounted ~ cardServicesSubscription:", cardServicesSubscription)
})
onUnmounted(() => {
    removeCardServiceSubscription(cardServicesSubscription)
    console.log("🚀 ~ onUnmounted ~ removeCardServiceSubscription(cardServicesSubscription):", removeCardServiceSubscription(cardServicesSubscription))
});
vejja commented 3 months ago

It's an upstream issue with https://github.com/Talljack/unplugin-remove.git Will file a report there

In the meantime, can you try disable the functionality in nuxt.config.ts

export default defineNuxtConfig({
  security: {
    removeLoggers: false
  }
})

And let me know if it works ?

Baroshem commented 3 months ago

Thanks @vejja for taking care of it!

@nosizejosh let us know if that works for you

nosizejosh commented 3 months ago

@vejja Thanks for the quick response.

Yes! build passed on both local and prod server.

Thank you for the package ( though I am now trying to understand how to really use it)

Will keep this open until a final resolution.

vejja commented 3 months ago

No problems @nosizejosh ! FYI removeLoggers is a small additional utility to the core of Nuxt-Security that removes console.log outputs in production. We are using the unplugin-remove package to do so but apparently there is a bug there and I think it is related to emojis. By setting removeLoggers: false in the config, we are not purging the browser console from your logs, but the rest of the Nuxt-Security core is still active.

In summary, you are good to go with this setup. Just remember that you may want to clean up your logs in your final production build.

vejja commented 3 months ago

@Baroshem FYI upstream was fixed today

Baroshem commented 3 months ago

Awesome, thanks @vejja !

I will add a bump of the package on our side and release it with the upcoming 1.3.0 release :)