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

ConfirmationService: require is not defined #1897

Closed
ValentinCrochemore opened this issue Dec 16, 2021 · 5 comments
Closed

ConfirmationService: require is not defined #1897

ValentinCrochemore opened this issue Dec 16, 2021 · 5 comments
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@ValentinCrochemore
Copy link

ValentinCrochemore commented Dec 16, 2021

I'm submitting a ... (check one with "x")

[x] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already  https://github.com/primefaces/primevue/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=110

Current behavior
Whenever my code contains confirm.require() the app breaks with ReferenceError: require is not defined. When I inspect this error in browser I can indeed see const { defineComponent } = require('vue'); added in the component where I included confirm.require(). This defineComponent seems to not be used and if I comment confirm.require(), the error and the require goes away.

Expected behavior
It should not add const { defineComponent } = require('vue'); when using confirm.require()

Minimal reproduction of the problem with instructions
https://codesandbox.io/s/bug-primevue-nuxt-3-bnq9d?file=/pages/test.vue
The page index.vue is there to illustrate that the app works fine. Note that the codesandbox repro is not ideal and has sometimes bugs not related to this one. If you want to reproduce locally please follow this link and copy/paste plugins/primevue.ts & test.vue from codesandbox.

What is the motivation / use case for changing the behavior?
The use case is displaying a confirm dialog when clicking a button. The behavior that should be change is adding const { defineComponent } = require('vue'); when calling confirm.require(). I looked in the source code and could not find where it would happen

Please tell us about your environment:

  • Linux version: 20.04

  • Vue version: 3.2.22

  • Nuxt version: 3.0.0-27296172.f5307f9

  • Vite version: 2.6.14

  • PrimeVue version: 3.10.0

  • Browser: all

@tugcekucukoglu tugcekucukoglu added the Type: Bug Issue contains a bug related to a specific component. Something about the component is not working label Dec 21, 2021
@tugcekucukoglu tugcekucukoglu added this to the 3.x milestone Dec 21, 2021
@tugcekucukoglu tugcekucukoglu self-assigned this Dec 21, 2021
@tugcekucukoglu tugcekucukoglu changed the title ReferenceError: require is not defined ConfirmationService: require is not defined Dec 21, 2021
@tugcekucukoglu tugcekucukoglu modified the milestones: 3.x, 3.10.1 Dec 23, 2021
@adlpz
Copy link

adlpz commented Jan 19, 2022

This issue still occurs in 3.11.0. Tried both in a local project and by forking the linked codesandbox and bumping primevue to 3.11.0. Same exact error.

However if you simply refer to this function by another name, the error disappears:

// If this code is present, Nuxt 3 fails to even compile:
confirm.require({message: 'U sure?'})

// However, this works flawlessly:
const doTheDialog = confirm.require
doTheDialog({message: 'U sure?'})

Looks like it is some obscure issue with the require(...) word itself, probably colliding with the built-in Node function when doing SSR, or the other way around. I'm afraid this whole transpiler vodoo is well above my paygrade.

Hope this helps.

@ValentinCrochemore
Copy link
Author

Haha it works ! I would never have guessed. Thanks a lot !

@jmverges
Copy link
Contributor

jmverges commented Feb 8, 2022

Thanks @adlpz took me all the morning. Shouldn't be this issue reopened?

@kmuip
Copy link

kmuip commented Mar 9, 2022

@adlpz Thanks, that did the job :)

I used the following in my code:

const { require: confirmRequire } = useConfirm()

@andreas83
Copy link

andreas83 commented May 28, 2024

Nuxt: 3.11.2
Node: 18.18.0
Primevue: 3.52.0

vie console.log i can see the function require is defined, but calling it results in nothing. no error or warning.

Screenshot_20240528_132214

i can just guess this is still somehow related with the reserved require keyword.

update

const {require: confirmRequire} = useConfirm();

console.log(confirmRequire); 

// returns a function ƒ require2(options) {
//        ConfirmationEventBus.emit("confirm", options);
//    }

// but following will give a undefined:

console.log(confirmRequire({
    message: 'Wollen Sie diese Anmerkung wirklich löschen?',
    header: 'Anmerkung löschen',
    icon: 'pi pi-info-circle',
    acceptClass: 'p-button-danger',
    accept: () => {
        deleteComment(e);
    },
    reject: () => {
    }
})));

update 2

okay found the reason, i simply was not aware that the confirm.require method relays on the ConfirmDialog component.

at least 2 hours wasted. thanks anyways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests

5 participants