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

Uncaught TypeError: The "original" argument must be of type Function when importing 'better-sqlite3' #8133

Closed
Kindnessfruit opened this issue May 24, 2022 · 7 comments

Comments

@Kindnessfruit
Copy link

Kindnessfruit commented May 24, 2022

🐛 bug report

Parcel failed to bundle npm package 'better-sqlite3'.

How to reproduce:
Just create an empty environment with 'better-sqlite3' as dependency and use the import statement on it.

import sqlt3 from "better-sqlite3"

*Parcel autoinstalled polyfill for Node builtin modules "process", "path", "util" before development server is built.

🎛 Configuration (.babelrc, package.json, cli command)

package.json:

{
  "type": "module",
  "name": "richtextprocessor",
  "version": "1.0.0",
  "description": "",
  "main": "lib.js",
  "scripts": {
    "start": "parcel frontpage.html"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "better-sqlite3": "^7.5.3",
    "bluebird": "^3.7.2",
    "express": "^4.18.1",
    "puppeteer": "^14.1.0"
  },
  "devDependencies": {
    "parcel": "^2.5.0",
    "path-browserify": "^1.0.1",
    "process": "^0.11.10",
    "util": "^0.12.4"
  }
}

🤔 Expected Behavior

(no error)

😯 Current Behavior

Error logged in chromium's console (similar in firefox):
util.js:614 Uncaught TypeError: The "original" argument must be of type Function
--at promisify (util.js:614:11)
--at Object.4Sc93.fs (backup.js:6:18)
--at newRequire (frontpage.81135c31.js:71:24)
--at localRequire (frontpage.81135c31.js:84:35)
--at Object.bRjc7.buffer (database.js:72:29)
--at newRequire (frontpage.81135c31.js:71:24)
--at localRequire (frontpage.81135c31.js:84:35)
--at Object.37mur../database (index.js:2:18)
--at newRequire (frontpage.81135c31.js:71:24)
--at localRequire (frontpage.81135c31.js:84:35)

firefox:
Uncaught TypeError: The "original" argument must be of type Function
--promisify util.js:614
--["4Sc93"]< backup.js:6
--newRequire frontpage.81135c31.js:71
--localRequire frontpage.81135c31.js:84
--bRjc7 database.js:72
--newRequire frontpage.81135c31.js:71
--localRequire frontpage.81135c31.js:84
--["37mur"]< index.js:2
--newRequire frontpage.81135c31.js:71
--localRequire frontpage.81135c31.js:84
--awQL6 fp.js:1
--newRequire frontpage.81135c31.js:71
-- frontpage.81135c31.js:122
-- frontpage.81135c31.js:145
util.js:614:10
--promisify util.js:614
--["4Sc93"]< backup.js:6
--newRequire frontpage.81135c31.js:71
--localRequire frontpage.81135c31.js:84
--bRjc7 database.js:72
--newRequire frontpage.81135c31.js:71
--localRequire frontpage.81135c31.js:84
--["37mur"]< index.js:2
--newRequire frontpage.81135c31.js:71
--localRequire frontpage.81135c31.js:84
--awQL6 fp.js:1
--newRequire frontpage.81135c31.js:71
-- frontpage.81135c31.js:122
-- frontpage.81135c31.js:145

💁 Possible Solution

🔦 Context

'better-sqlite3'.

💻 Code Sample

How to reproduce:
Just create an empty environment with 'better-sqlite3' as dependency and use the import statement on it.

🌍 Your Environment

Software Version(s)
Parcel 2.5.0
Node v16.14.2.
npm 6.14.17
Operating System Windows 10
@mischnic
Copy link
Member

The error comes from this line:

https://github.com/WiseLibs/better-sqlite3/blob/f52b3b00cf03090619787a20fb263fec553593ff/lib/methods/backup.js#L6

The fs "polyfill" provided by Parcel just does module.exports = {}. So fs.access will be undefined and then promisify(undefined) fails.

As far as I can tell, better-sqlite3 is not designed to run in the browser?

@Kindnessfruit
Copy link
Author

Kindnessfruit commented May 25, 2022

The error comes from this line:

https://github.com/WiseLibs/better-sqlite3/blob/f52b3b00cf03090619787a20fb263fec553593ff/lib/methods/backup.js#L6

The fs "polyfill" provided by Parcel just does module.exports = {}. So fs.access will be undefined and then promisify(undefined) fails.

As far as I can tell, better-sqlite3 is not designed to run in the browser?

I am trying to extract texts from books in a sqlite database. I have tried to bundle node-sqlite3 using parcel as well, but that failed too, so this is really an awkward situation. https://ibb.co/zJS9bmk

@mischnic
Copy link
Member

mischnic commented May 25, 2022

Also, both node-sqlite3 and better-sqlite3 use native Node modules. So there is no way to run them in the browser even if you managed to bundle them.

@Kindnessfruit
Copy link
Author

Also, both node-sqlite3 and better-sqlite3 use native Node modules. So there is no way to run them in the browser even if you managed to bundle them.

Thank you for your patience. I am really new to web development I am not really sure what bundlers does, but I have found a tutorial that helped me out. Thank you, and all the best (qdV9S7UE99o).

@VarmaDev390
Copy link

VarmaDev390 commented Jun 22, 2023

hai @Kindnessfruit can you please share, on how you solved this error

@Kindnessfruit
Copy link
Author

hai @Kindnessfruit can you please share, on how you solved this error

@VarmaDev390 I didn't understand the difference between client and server side back then, so I was trying to package better-sqlite3 and executing that on the client side. I solved the problem by avoid using better-sqlite3 on the client side.

@VarmaDev390
Copy link

VarmaDev390 commented Jul 7, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants