nexus-prisma: Doesn't work with ES modules

Hello ๐Ÿ‘‹๐Ÿป

As I can see #124 was implemented but I have some problems with it. When I try to import nexus-prisma it still tries to import cjs module so I get errors trying to run my app.

Any ideas? type is set to โ€˜moduleโ€™ and nexus-prisma is imported using โ€œimportโ€ keyword

image

EDIT: If I change import to

import nexusPrisma from 'nexus-prisma';

const {FuelStation} = nexusPrisma

then I get the following error:

(node:56355) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
/Volumes/Workspace/pets/cheapoil/core/node_modules/nexus-prisma/dist-esm/entrypoints/main.js:1
import { inspect } from 'util';
^^^^^^

SyntaxError: Cannot use import statement outside a module

_Originally posted by @MikeYermolayev in https://github.com/prisma/nexus-prisma/discussions/141_

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 3
  • Comments: 17 (6 by maintainers)

Most upvoted comments

ES modules is still not work. To use @apollo/server , i have to change my type to module. When i run my project, some error shown:

import { User } from 'nexus-prisma';
         ^^^^
SyntaxError: Named export 'User' not found. The requested module 'nexus-prisma' 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 'nexus-prisma';
const { User } = pkg;

And i make this change and restart, some error throw:

node_modules\.pnpm\nexus-prisma@1.0.4_63udwhd7sp4du2rzhags75opna\node_modules\nexus-prisma\dist-esm\entrypoints\main.js:1
import { inspect } from 'util';
^^^^^^

SyntaxError: Cannot use import statement outside a module

https://github.com/graphql-nexus/nexus-prisma/discussions/141

Looks like the problem is in wrong build for esm. Imports inside esm should contain extensions but as I can see they donโ€™t.

Iโ€™ll try to look into this during this week (Nov 17- Nov 21)

I have a problem with new Next.js 12 and nexus-prisma, it gives me error something like nexus-prisma dependency @client/prisma is not installed, ofc it is installed and reverting to last version of Next.js fixes problem. It is probably something similar to problems other people have with es modules.

No worries @jasonkuhrt, no rush on my side (also I think the error is something on my end or with TS, will report back if I manage to fix)