Description
Version: Deno 2.1.1
Hello,
First of all, I’m really excited about the improvements in Deno 2.1.
However, since Deno 2.1 fixed the bug where files required from .cjs files were automatically treated as CommonJS, I've been unable to import Prisma Client.
I understand that this is not an issue with Deno itself, but rather one of the many compatibility issues with Prisma.
Nevertheless, as it relates to Deno's compatibility with CommonJS, I'd like to ask a question here.
Before Deno 2.1, we used a helper script to import Prisma Client:
// prisma-client.cjs
const mod = require("./generated/client/index.js");
Object.keys(mod).forEach((key) => {
exports[key] = mod[key];
});
// prisma-client.ts
// @deno-types="./generated/client/deno/index.d.ts"
export * from "./prisma-client.cjs";
This allowed imports in other script files like:
// foo.ts
import { PrismaClient } from "./prisma-client.ts";
This approach depended on the behavior fixed in Deno 2.1, where files required from .cjs were automatically considered CommonJS.
When updating to Deno 2.1, I expected that this helper script would become unnecessary and that we could import like this:
// package.json
{
"type": "commonjs",
// other settings here...
}
// foo.ts
import { PrismaClient } from "./generated/client/index.js";
Unfortunately, this didn't work as expected because Prisma generates its own package.json file in ./generated/client/package.json
, which doesn't include "type": "commonjs".
Since there are several situations Prisma Client is regenerated, modifying ./generated/client/package.json
or changing filenames to .cjs
after each regeneration isn't a sustainable solution.
I’d really appreciate any advice or suggestions on how to fix this situation.
Thank you!