Skip to content
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

Build fails because of removeLoggers #306

Closed
vejja opened this issue Nov 28, 2023 · 2 comments · Fixed by #311
Closed

Build fails because of removeLoggers #306

vejja opened this issue Nov 28, 2023 · 2 comments · Fixed by #311
Labels
bug Something isn't working

Comments

@vejja
Copy link
Collaborator

vejja commented Nov 28, 2023

Version

nuxt-security: 1.0.0-rc.4
nuxt: 3.8.2

Reproduction Link

https://stackblitz.com/edit/nuxt-starter-tsqs5c?file=README.md

Steps to reproduce

Open Stackblitz repro
Observe the test function in app.vue : it has a console.log that works fine in dev mode (yarn dev)

What is Expected?

App should build successfully

What is actually happening?

Build fails with Unexpected token (Note that you need plugins to import files that are not JavaScript)

Capture d’écran 2023-11-28 à 17 29 55

Another variant can also happen in ts files : [vite:build-import-analysis] Parse error @:1:1

I'm not providing a repro because it would be too long to set up, but screenshot below on a Pinia store file:

Sans titre

Bug Analysis

The bug happens when console.log is removed from a lambda void-returning arrow-syntax function with a single instruction.
I guess the parser is a bit too aggressive and transforms :

const test = () => console.log('Test')

Into

const test = () =>

Which is invalid Javascript

Solution

This is not a Nuxt-Security bug, this comes from unplugin-remove

Upstream Issue opened at : Talljack/unplugin-remove#3

Temporary Solution for Nuxt-Security : If you encounter this issue, you can either :

  • set removeLoggers: false
  • refactor above code to const test = () => { console.log('Test') }
@Baroshem
Copy link
Collaborator

Baroshem commented Dec 2, 2023

Hey @vejja

Thank you so much about finding this bug and also finding a solution to it :)

I will merge it in the upcoming 1.0.0.rc.5 version :)

@vejja vejja mentioned this issue Dec 4, 2023
6 tasks
@vejja
Copy link
Collaborator Author

vejja commented Dec 4, 2023

PR #311 fixes

@vejja vejja linked a pull request Dec 4, 2023 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants