unjs / unimport

Unified utils for auto importing APIs in modules.
MIT License
515 stars 60 forks source link

Nuxt: useHead undefined after initiating a regex (since monday) #346

Open hankdetank opened 4 months ago

hankdetank commented 4 months ago

Environment

Linux (this problem doesnt appear to happen on windows). tested on different node versions.

Reproduction

https://stackblitz.com/edit/github-819pq2-4sknkq?file=layouts%2Fdefault.vue

Describe the bug

"var emailregexx = /^[a-zA-Z0-9.!#$%&'+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:.[a-zA-Z0-9-]+)$/; useHead({ meta: [ { name: 'viewport', content: 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0', }, ], });"

This code crashes. And my question is why. I've created an issue on nuxt at: https://github.com/nuxt/nuxt/issues/27392 . There danielroe asked me to created to ticket here.

It happens since monday(maybe friday or thursday) and this code is already years old.

When you remove the regex line, all works normally again.

When you change the regex to the following 2 options it works: /^[a-zA-Z0-9.!#$%&'+/?{|}~-]+@[a-zA-Z0-9-]+(?:.[a-zA-Z0-9-]+)$/; (removed the `)

/^[a-zA-Z0-9.!#$%&'+\/?`{|}~-]+@[a-zA-Z0-9-]+(?:.[a-zA-Z0-9-]+)$/; (escaped the /)

Additional context

Error that gets thrown: useHead is not defined

at _sfc_main.setup (./layouts/default.js:42:23) at callWithErrorHandling (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:195:19) at setupStatefulComponent (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7572:25) at setupComponent (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7533:36) at renderComponentVNode (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:623:15) at renderVNode (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:755:14) at renderComponentSubTree (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:710:7) at eval (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:639:25) at async unrollBuffer$1 (./node_modules/@vue/s

Logs

No response

manniL commented 4 months ago

@hankdetank please provide an unimport-only reproduction next time 😋

Example (using only unimport here) reproduction in this case