The problem of not being able to use a npm library in extension development using import or require can be resolved if you use vite build tool to develop the project.
Create a new vite project npm create vite@latest
Must keep the manifest.json and icons inside the public folder. You can refer to the following folder structure. enter image description here
Build the project npm run build
and your extension is ready to be tested inside the dist folder.
Now you can install and use any npm library seamlessly.
I feel this process is a bit tricky to debug if the codebase is bigger.