nexus-plugin-prisma icon indicating copy to clipboard operation
nexus-plugin-prisma copied to clipboard

@nexus/schema must be installed as a dependency on webpack build

Open watanabeyu opened this issue 4 years ago • 8 comments

Hi there. I get a below error when I try to run build by webpack.

ERROR: @nexus/schema must be installed as a dependency. Please run `npm install @nexus/schema`.

@nexus/schema is in a package.json's dependencies. I didn't get this error run build by tsc.

Please let me know how to build with webpack.

watanabeyu avatar Nov 04 '20 10:11 watanabeyu

Duplicate of #843

Sebdevar avatar Nov 18 '20 23:11 Sebdevar

Can you please show me your webpack.config? We just managed to fix it on our end.

The plugin should be part of externals along with prisma and nexus/schema. You also need to make sure it's imported correctly in your project (if externals is nexus-plugin-prisma, then importing from 'nexus-plugin-prisma/schema' will throw an error and vice-versa)

Sebdevar avatar Nov 25 '20 18:11 Sebdevar

Can you please show me your webpack.config? We just managed to fix it on our end.

The plugin should be part of externals along with prisma and nexus/schema. You also need to make sure it's imported correctly in your project (if externals is nexus-plugin-prisma, then importing from 'nexus-plugin-prisma/schema' will throw an error and vice-versa)

Could you create a repo with a simplified version of your setup? I'm coming from one of the Prisma examples so I'm not using webpack, but I'm very confused how I could set up Webpack to compile my project.

leo-petrucci avatar Nov 26 '20 13:11 leo-petrucci

I am also affected @creativiii

ERROR: nexus must be installed as a dependency. Please run `npm install nexus`.

My webpack config.

const serverlessWebpack = require('serverless-webpack');
const CopyPlugin = require("copy-webpack-plugin");

module.exports = {
  target: 'node',
  devtool: 'inline-source-map',
  entry: serverlessWebpack.lib.entries,
  mode: serverlessWebpack.lib.webpack.isLocal ? 'development' : 'production',
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: 'ts-loader',
        exclude: /node_modules/,
      },
    ],
  },
  resolve: {
    extensions: ['.tsx', '.ts', '.js'],
  },
  optimization: {
    minimize: false,
  },
  plugins: [
    new CopyPlugin({
      patterns: [
        {
          from: "node_modules/.prisma/client/query-engine-rhel-openssl-1.0.x",
          to: "node_modules/.prisma/client/query-engine-rhel-openssl-1.0.x"
        },
      ],
    }),
  ],
};

Would you consider another workaround for function ensureDepIsInstalled(depName: string)? Webpack cannot resolve this during the build.

aniruddha-adhikary avatar Dec 22 '20 00:12 aniruddha-adhikary

I came across the same:

ERROR: nexus must be installed as a dependency. Please run `npm install nexus`.

in a Rush monorepo, and traced it down to my schema file which had these imports:

import { nexusPrisma } from 'nexus-plugin-prisma';
import { makeSchema } from 'nexus';

Switching the imports around "fixed it".

djm avatar Jan 17 '21 23:01 djm

Received the same error when attempting a deploy to Heroku:

remote: ERROR: nexus must be installed as a dependency. Please run `npm install nexus`.

Couldn't replicate locally.

The solution above of switching the nexus import order solved the issue - thanks @djm!

robmorieson avatar Feb 24 '21 00:02 robmorieson

@djm I am getting the same error ? nexus must be installed as a dependency. Please run npm install nexus. my imports are like this and still getting error

import { nexusPrisma } from 'nexus-plugin-prisma'; import { makeSchema } from 'nexus';

also can you tell me the exact versions of these modules?

mohsinamjad avatar Mar 07 '21 08:03 mohsinamjad

I can't believe I forgot to post here. Turns out the problem is likely not related to nexus-plugin-prisma at all. After extensive research and trial and error I think this is caused by Prisma incorrectly not generating types.

We had an extensive talk about it prisma/prisma#5175 with some solutions.

I've also set up a simple boilerplate for Serverless Prisma projects https://github.com/coloredcat/serverless-prisma-vercel-boilerplate

leo-petrucci avatar Mar 16 '21 16:03 leo-petrucci