Use require in vue3 project with bun – not working: require is not defined

  Kiến thức lập trình

I have a question about using a common js package in a new vue3 project.
const io = require('socket.io') with an older socket.io version (v2).
However, it does not really matter which package I am requiring.

After realising that the browser will return ReferenceError: require is not defined I looked for alternatives and found that Bun should be able to handle all these problems:

https://bun.sh/docs/runtime/modules#using-import-and-require-together

It claims

In Bun, you can use import or require in the same file—they both work, all the time.

I thought, well perfect, that is what I need. I reinstalled all node_modules with bun and started the app $ bun dev.
But still I would get the same error.

Do I oversee something?

LEAVE A COMMENT