Cannot integrate Optimize into Node.js ESM project

I'm trying to integrate Prisma Optimize into my JS project. After following the guide, I ran into the following error:
file:///home/micc/projects/optimize-playground/node_modules/@prisma/extension-optimize/dist/index.js:1
// ....
SyntaxError: Named export 'PrismaInstrumentation' not found. The requested module 'prisma-instrumentation-5-x' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'prisma-instrumentation-5-x';
const {trace: Kt}from"@opentelemetry/api";......
file:///home/micc/projects/optimize-playground/node_modules/@prisma/extension-optimize/dist/index.js:1
// ....
SyntaxError: Named export 'PrismaInstrumentation' not found. The requested module 'prisma-instrumentation-5-x' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'prisma-instrumentation-5-x';
const {trace: Kt}from"@opentelemetry/api";......
It looks like the import syntax used in @prisma/extension-optimize doesn't work in a pure Node.js environment without TypeScript transpilation. Here's a minimal reproducible example: https://github.com/MiccWan/prisma-issue-optimize Please let me know if any additional info would help.
GitHub
GitHub - MiccWan/prisma-issue-optimize
Contribute to MiccWan/prisma-issue-optimize development by creating an account on GitHub.
9 Replies
Prisma AI Help
Skipping coffee for instant knowledge! Let's brew that AI answer now. The error you're encountering—SyntaxError: Named export 'PrismaInstrumentation' not found. The requested module 'prisma-instrumentation-5-x' is a CommonJS module...—is due to ESM/CommonJS interop issues. This is a known problem when using Prisma extensions (like Optimize) or instrumentation in pure ESM (vanilla JS) projects, as some Prisma packages (including @prisma/instrumentation and dependencies used by @prisma/extension-optimize) are still published as CommonJS modules and do not provide named exports for ESM import syntax. Workarounds: - Instead of using ESM named imports, use the default import and destructure:
import pkg from 'prisma-instrumentation-5-x';
const { PrismaInstrumentation } = pkg;

import pkg from 'prisma-instrumentation-5-x';
const { PrismaInstrumentation } = pkg;

This pattern is also recommended for @prisma/instrumentation and similar packages until full ESM support is available source. - Alternatively, you can use createRequire from the Node.js module API in ESM files:
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const { PrismaInstrumentation } = require('@prisma/instrumentation');

import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const { PrismaInstrumentation } = require('@prisma/instrumentation');

This workaround is confirmed to work for similar issues with Prisma packages in ESM environments source. Current Status: - Prisma Client and its extensions are not yet fully ESM-compatible. This limitation affects direct named imports in vanilla JS/ESM projects source. - There is ongoing work to improve ESM support, but for now, the above workarounds are necessary. If you continue to have issues, consider running your project with a transpiler (like TypeScript or Babel), or follow updates on Prisma's ESM support in their GitHub issues. If you need further help, please provide your Node.js version and Prisma package versions, as some issues may be resolved in newer releases. 🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
MiccWan
MiccWanOP3w ago
I looked deeper into the issue and found that 'prisma-instrumentation-5-x' actually refers to @prisma/instrumentation@5.19.1, which only provides CommonJS exports and doesn’t support ESM. Because of that, when @prisma/extension-optimize imports it in a pure Node.js ESM environment, it throws a strict import type error. This doesn’t happen when using TypeScript + a transpiler (like tsx), since transpilation relaxes those checks. A proper fix would be to update @prisma/instrumentation@5.19.1 to include an "exports" field in its package.json—like in version 6—so it supports both CommonJS and ESM.
Nurul
Nurul3w ago
We are working on adding native support for ESM with Prisma 7. I believe it should be fixed then. Thanks for sharing the solution though 🙏
Kenzo
Kenzo3w ago
hi! I keep trying things but I have this similar issue. can PrismaClient work in a node app using "moduleResolution": "NodeNext", "module": "NodeNext"?
No description
Kenzo
Kenzo3w ago
moduleResolution": "NodeNext" foces me to use direct imports, and import { PrismaClient } from './generated/prisma/client.js' always gives me an error
Kenzo
Kenzo3w ago
been testing with diferent generator options, but nothing 🙁
No description
Kenzo
Kenzo3w ago
and yes I generated it a lot of times, testing everything, and deleting also the dist -- nvm i heard Prisma doesn't support ES6 modules yet, should warned on the docs
MiccWan
MiccWanOP2w ago
Hi @Kenzo Prisma ORM (but not Optimize) should work fine in a native Node ESM / NodeNext setup. The issue is likely with path resolution or config, not Prisma itself. If you can share a minimal reproducible example, I’d be happy to help debug it.
MiccWan
MiccWanOP2w ago
I put together a minimal example based on your setup. It uses pnpm, tsc, and "moduleResolution": "nodenext": https://github.com/MiccWan/prisma-ts-playground
GitHub
GitHub - MiccWan/prisma-ts-playground
Contribute to MiccWan/prisma-ts-playground development by creating an account on GitHub.

Did you find this page helpful?