apache / apache/pouchdb

TypeError issue in the browser with `Object` being undefined (SSR with vite)

Open
#8,535 8 comments 1 reaction 0 assignees View on GitHub
stale
Dominant language
JavaScript
Stars
17.6k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

### Issue
When building a project using `pouchdb` with `vite` (`vite build`), everything runs smoothly when building or running the dev server, but then we get this when loading the SSR generated static files in the browser

```
Uncaught TypeError: Object prototype may only be an Object or null: undefined
at Function.create ()
at Object.create.Ve.exports (index.70e0c1cf.js:32:921)
at index.70e0c1cf.js:32:5677
```

Minified excerpt:
```
typeof Object.create=="function"?Ne.exports=function(t,n){n&&(t.super_=n,t.prototype=Object.create(n.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:
```
image

I have shimmed the `global` issue (#8516 ), but then am stuck on this one and cannot find exactly where this is defined. The closest I came was finding this code, which seems to match the minified version:

```
module.exports = function inherits(ctor, superCtor) {
ctor.super_ = superCtor
ctor.prototype = Object.create(superCtor.prototype, {
constructor: {
value: ctor,
enumerable: false,
writable: true,
configurable: true
}
});
};
```
https://github.com/pouchdb/npm-browser/blob/41a57412d020a8a8acdf91d11deeb113ca39df0d/scripts/deps/pouchdb.load.js#L962-L972

### Info
- Environment: Node.js SSR, error shows up in the browser
- Platform:Chrome
- Adapter: indexeddb IIRC (the default)
- Server: CouchDB

### Reproduce
Minimalish fresh repo reproducing the issue (`vite`, `vue`, `vuetify`, and `pouchdb`). To build the site, `npm run build`
https://github.com/colearendt/js-issue-20220729

Live site: https://colearendt.github.io/js-issue-20220729/

### Opinions

It seems to me that `pouchdb` has a _lot_ of potential value in the SSR / PWA story. However, without some of these rough edges removed, I am likely to just implement my own client library for `CouchDB` using `axios` or something like that. I lose the benefit of local storage and sync, but at least I can build the site / host it cheaply 😄

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.