Skip to content

Instantly share code, notes, and snippets.

@tanishqmanuja
Created September 8, 2024 14:34
Show Gist options
  • Save tanishqmanuja/726fd74a9d1ac98c5848cf724086482c to your computer and use it in GitHub Desktop.
Save tanishqmanuja/726fd74a9d1ac98c5848cf724086482c to your computer and use it in GitHub Desktop.
PGLite with angular 17+

1) Error 1 - Prebundling

1

Solution:
disable prebundling all together for dev server

"serve": {
  "builder": "@angular-devkit/build-angular:dev-server",
  "configurations": { ... }
  "defaultConfiguration": "development",
  "options": {
    "prebundle": false
  }
},

after solving prebundling this will lead to the next error

2) Error 2 - Conditional node specific import of "util"

2

Solution:
mark "util" as external package, this works becuase util is not actually used in web/browser env but still import is enough to annoy the compiler.

"build": {
  "builder": "@angular-devkit/build-angular:application",
  "options": {
    ...
    ...
    "styles": ["src/styles.scss"],
    "scripts": [],
    "externalDependencies": ["util"]
  },
}

this will still lead to another error, that looks similar to Error 1 but is not.

3) Error 3 - Bundling postgres.wasm and postgres.data

3

Solution:
this is fairly simple to resolve, just add them to the assets array

"build": {
  "builder": "@angular-devkit/build-angular:application",
  "options": {
    ...
    ...
    "assets": [
        {
          "glob": "**/*",
          "input": "public"
        },
        {
          "input": "node_modules/@electric-sql/pglite/dist",
          "glob": "postgres.(data|wasm)"
        }
      ],
    "styles": ["src/styles.scss"],
    "scripts": [],
    "externalDependencies": ["util"]
  },
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment