You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Outside of any potential ESM issues, the require('../package.json') code makes @prisma/instrumentation incompatible with many bundlers out of the box.
The next version of @sentry/node will hopefully have @prisma/instrumentation as a dependency so that instrumentation works without any special configuration but currently this will stop consumers of @sentry/node from bundling their code unless their bundler supports json. Even if their bundler does support json, the entire package.json will get included in the bundle.
Reacted by Serhii Tatarintsev, Alberto Schiabel and Danilo Fuchs
@SevInf I'm not an expert by any means, but I'm currently moving my server build to ESM with esbuild and the only package that esbuild has issues with is @prisma/instrumentation. Prisma Client seems to be doing just fine.
Use readFileSync and JSON.parse instead of require so biundlers don't pick it up as a dependency. It'll need a try/catch and a fallback version as it will likely fail to find the file if the code gets bundled
Have a version string placeholder in the code which gets overwritten before publish
@SevInf would you accept PRs for this change? Or could we get it prioritized in another way? We'd love to have Prisma instrumentation out-of-the-box for Sentry, this would help a lot!
Just checked the latest release and the bundling of @prisma/instrumentation means there's no longer a require('../package.json') in the distributed code any more.
Providing an ESM build (alongside the CJS build) would be helpful for codebases that use ESM and import @prisma/instrumentation. Currently when importing @prisma/instrumentation in a fresh Node.js/ESM project, importing does not work with named exports:
import { PrismaInstrumentation } from "@prisma/instrumentation";
^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Named export 'PrismaInstrumentation' not found. The requested module '@prisma/instrumentation' 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';
const { PrismaInstrumentation } = pkg;
at ModuleJob._instantiate (node:internal/modules/esm/module_job:134:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:217:5)
at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)
at async loadESM (node:internal/process/esm_loader:28:7)
at async handleMainPromise (node:internal/modules/run_main:113:12)
Node.js v20.12.2
Reacted by Danilo Fuchs, Michał Ciężczak and David Dios
Activity
SevInf commentedon Mar 14, 2024
Considering prisma client itself is not yet ESM-compatible, what benefits would converting just
@prisma/instrumentationbring?timfish commentedon Mar 14, 2024
Outside of any potential ESM issues, the
require('../package.json')code makes@prisma/instrumentationincompatible with many bundlers out of the box.The next version of
@sentry/nodewill hopefully have@prisma/instrumentationas a dependency so that instrumentation works without any special configuration but currently this will stop consumers of@sentry/nodefrom bundling their code unless their bundler supports json. Even if their bundler does support json, the entirepackage.jsonwill get included in the bundle.patjakubik commentedon Apr 1, 2024
@SevInf I'm not an expert by any means, but I'm currently moving my server build to ESM with esbuild and the only package that esbuild has issues with is @prisma/instrumentation. Prisma Client seems to be doing just fine.
timfish commentedon Apr 2, 2024
There are two options that I can see:
readFileSyncandJSON.parseinstead ofrequireso biundlers don't pick it up as a dependency. It'll need a try/catch and a fallback version as it will likely fail to find the file if the code gets bundledAbhiPrasad commentedon Apr 15, 2024
@SevInf would you accept PRs for this change? Or could we get it prioritized in another way? We'd love to have Prisma instrumentation out-of-the-box for Sentry, this would help a lot!
timfish commentedon Apr 24, 2024
Just checked the latest release and the bundling of
@prisma/instrumentationmeans there's no longer arequire('../package.json')in the distributed code any more.Thanks!
feat(node): Upgrade @prisma/instrumentation to 5.13.0 (#11779)
ericallam commentedon Jul 15, 2024
Providing an ESM build (alongside the CJS build) would be helpful for codebases that use ESM and import
@prisma/instrumentation. Currently when importing@prisma/instrumentationin a fresh Node.js/ESM project, importing does not work with named exports:Results in the following error:
champikasam commentedon Sep 19, 2024
I am seeing the same error as @ericallam . I have imported the full module as suggested there. Would be good to have a named export working.
kentcdodds commentedon Feb 4, 2025
Just tossing my experience in the ring as well. I had a failed build because of this, and here's what I had to do: epicweb-dev/epic-stack@b647d19
build(instrumentation): Emit ESM (prisma#26918)