drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.52k stars 643 forks source link

[BUG]: drizzle-orm ^0.26.1 requires top-level-await to be set to true in Next JS 13 #662

Closed jackvane closed 1 year ago

jackvane commented 1 year ago

What version of drizzle-orm are you using?

0.26.2

What version of drizzle-kit are you using?

0.18.1

Describe the Bug

Just bumped drizzle-orm to 0.26.2 from 0.26.0 and I received this error while querying:

- error ./node_modules/drizzle-orm/relations-d3070559.mjs
Module parse failed: The top-level-await experiment is not enabled (set experiments.topLevelAwait: true to enabled it)
Error: The top-level-await experiment is not enabled (set experiments.topLevelAwait: true to enabled it)
Import trace for requested module:
./node_modules/drizzle-orm/relations-d3070559.mjs
./node_modules/drizzle-orm/index.mjs
./src/app/ops/content/shows/loaders.tsx
./src/app/ops/content/shows/page.tsx
- warn Fast Refresh had to perform a full reload due to a runtime error.

This also happens if I do a bump to 0.26.1.

Note that this will resolve the error in Next JS, but would prefer not to hack any webpack configs to get this working.

/** @type {import('next').NextConfig} */
const nextConfig = {
  experimental: {
    serverActions: true,
  },
  webpack(config) {
    config.experiments = { ...config.experiments, topLevelAwait: true };
    return config;
  },
};

module.exports = nextConfig;

Expected behavior

No error.

Environment & setup

Node v19.0.0 Next 13.4.4

dankochetov commented 1 year ago

There is indeed a top-level await in the code now, caused by an optional OTEL runtime dependency, so this is expected. I don't think there's a way to avoid it.

cs-clarence commented 1 year ago

This is unfortunate for projects that is restricted to cjs which doesn't support TLA. I'm using solid start and vercel adapter and have no control over which type of module it produces (only cjs even if I specify esm in the config), so this update recent broke my deployment builds.

PhilBookst commented 1 year ago

Same problem here using sveltekit on cloudflare pages.

Maybe you could add an option to opt-out of telemtry?

AndriiSherman commented 1 year ago

https://github.com/drizzle-team/drizzle-orm/releases/tag/0.26.3

removed it in 0.26.3

AndriiSherman commented 1 year ago

Will put it back in later releases with different approach for setting it up