Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue in the migration of NestJs app using Prisma inside an NX monorepo. #1167

Open
BaptisteMahe opened this issue Dec 19, 2024 · 0 comments

Comments

@BaptisteMahe
Copy link

BaptisteMahe commented Dec 19, 2024

Summary

I am currently trying to migrate my NestJS application to use Nestia in my NX Monorepo. Still, I am encountering an issue which looks like it is related to the use of Prisma (I have another app already migrated that runs smoothly but it doesn't depend on my Prisma setup):

  • SDK Version: 6.1.0-dev.20240910-2
  • Expected behavior: The app should run.
  • Actual behavior:
    When running the project, an error like this appear:
TypeError: generated_1.PrismaClient is not a constructor
    at Object.../libs/core/models/src/prisma/client.ts
    at __webpack_require__
    ...

It seems like PrismaClient is not being properly initialized, and I suspect it might be due to the webpack config but I couldn't put my finger on it even while I followed your guide for it.
It's actually working when I remove the dependency on Prisma from the application.

My webpack.config.js for this project:

module.exports = composePlugins(
  withNx(),
  (config, { options, context }) => {
    return merge(config, {
      mode: process.env.ENVIRONMENT === "local" ? "development" : "production",
      cache: process.env.ENVIRONMENT === "local" ? {
        type: "filesystem",
        buildDependencies: {
          config: [__filename]
        },
        cacheDirectory: path.resolve(__dirname, "../../.cache/apps/backend/"),
        maxAge: 86400000
      } : false,
      entry: {
        "main": ["/libs/core/document/src/assets/scss/main.scss"],
        "commercial-support-document": [
          "/libs/core/document/src/assets/scss/commercial-support-document.scss"
        ]
      },
      module: {
        rules: [
          {
            test: /\.node$/i,
            use: ["node-loader"]
          },
          {
            test: /\.css$/,
            use: [MiniCssExtractPlugin.loader, "css-loader"]
          },
          {
            test: /\.s[ac]ss$/i,
            use: [
              MiniCssExtractPlugin.loader,
              "css-loader",
              "sass-loader"
            ]
          }
        ]
      },
      optimization: {
        minimizer: [`...`, new CssMinimizerPlugin()],
        minimize: process.env.ENVIRONMENT !== "local"
      },
      plugins: [
        new RemoveEmptyScriptsPlugin(),
        new MiniCssExtractPlugin({
          filename: "public/[name].css"
        }),
        process.env.ENVIRONMENT === "local" ? new SpeedMeasurePlugin() : null
      ],
      ignoreWarnings: [/Failed to parse source map/]
    });
  }
);

My tsconfig.json :

{
	"extends": "../../tsconfig.base.json",
	"files": [],
	"include": [],
	"references": [
		{
			"path": "./tsconfig.app.json"
		},
		{
			"path": "./tsconfig.spec.json"
		}
	],
	"compilerOptions": {
		"emitDecoratorMetadata": true,
		"experimentalDecorators": true,
		"esModuleInterop": true,
		"strict": true,
		"plugins": [
		  { "transform": "typia/lib/transform" },
		  {
			"transform": "@nestia/core/lib/transform",
			"validate": "assert",
			"stringify": "assert",
		  },
		  { "transform": "@nestia/sdk/lib/transform" },
		]
	}
}

Also, my Prisma setup is a bit different. I don't let Prisma generate the types Client inside the node_modules but rather keep them inside an NX Lib and export them through barrel files. Maybe this can cause the issue?

If there is any advice you can give me, I would greatly appreciate the guidance.
Thank you for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant