question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot work with prisma

See original GitHub issue
Serverless: Typescript compiled.
Serverless: Optimize: starting engines
Serverless: Optimize: accounts-dev-main
 
  Syntax Error -------------------------------------------
 
  SyntaxError: Unexpected token (19074:12) while parsing /Users//services/node_modules/@prisma/client/runtime/index.js while parsing file: /Users//services/node_modules/@prisma/client/runtime/index.js
      at DestroyableTransform.end [as _flush] (/Users//services/node_modules/insert-module-globals/index.js:114:21)

https://github.com/prisma/prisma/issues/5392#issuecomment-793100660

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:16

github_iconTop GitHub Comments

2reactions
softmarshmallowcommented, May 28, 2021

I’m switching to webpack and it works


plugins:
  # - serverless-bundle
  # - "serverless-plugin-typescript"
  - serverless-webpack
  # - "@hewmen/serverless-plugin-typescript"
  # - serverless-plugin-optimize
  - serverless-offline

custom:
  # bundle:
  #   packager: yarn
  #   linting: false
  #   tsConfig: "tsconfig.json"
  webpack:
    webpackConfig: webpack.config.js
    packager: 'yarn'
    includeModules: true # This is required
    packagerOptions:
      scripts: # this is the magic
        - prisma generate 

  serverless-offline:
    httpPort: 9000
  warmup:      
    - production
    - staging

const slsw = require("serverless-webpack");

const path = require("path");
const webpack = require("webpack");
const nodeExternals = require("webpack-node-externals");
const CopyWebpackPlugin = require("copy-webpack-plugin");

module.exports = {
  entry: slsw.lib.entries,
  // entry: ["./src/lambda.ts"],
  externals: [
    // { _http_common: "_http_common" },
    nodeExternals(), // this is required
  ],
  plugins: [
    new CopyWebpackPlugin({
      patterns: [{ from: "./prisma/schema.prisma" }],
    }), // without this the prisma generate above will not work

    // ...options.plugins,
    new webpack.IgnorePlugin({
      checkResource(resource) {
        const lazyImports = [
          "@nestjs/microservices",
          "@nestjs/platform-express",
          "@nestjs/websockets",
          "@nestjs/websockets/socket-module",
          "@nestjs/microservices/microservices-module",
          "@prisma/client",
          "cache-manager",
          "class-validator",
          "class-transformer",
        ];
        if (!lazyImports.includes(resource)) {
          return false;
        }
        try {
          require.resolve(resource);
        } catch (err) {
          return true;
        }
        return false;
      },
    }),
  ],
  module: {
    rules: [
      {
        test: /\.ts$/,
        loader: "ts-loader",
        include: [__dirname],
        exclude: /node_modules/,
      },
    ],
  },
  resolve: {
    extensions: [".ts", ".js"],
  },
  // output: {
  //   libraryTarget: "commonjs2",
  //   path: path.join(__dirname, ".webpack"),
  //   filename: "src/lambda.js",
  // },
};

1reaction
nguyenjkcommented, Feb 10, 2022

optimize: external: [‘@prisma/client’, ‘.prisma/client’]

@hoangtrieukd you save my life with these. confirm it works with these two line

custom: optimize: external: ['@prisma/client', '.prisma/client']

Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not resolve @prisma/client despite the installation that ...
i tried this solution (custom output path) but it doesn't work for me. package.json. "dependencies": { "@prisma/client": "2.29.0" }, " ...
Read more >
Prisma Migrate limitations and known issues
Prisma Migrate generates SQL files that are specific to your provider. This means that you cannot use the same migration files for PostgreSQL...
Read more >
Error message reference - Prisma
Prisma Client throws a PrismaClientRustPanicError exception if the underlying engine crashes and exits with a non-zero exit code. In this case, the Prisma ......
Read more >
Troubleshooting relations - Prisma
This will not work however as the relation table ( PostCategories ) must form a 1-to-many relationship with the other two models respectively....
Read more >
Handling exceptions and errors (Reference) - Prisma
import { PrismaClient, Prisma } from '@prisma/client' ... 'There is a unique constraint violation, a new user cannot be created with this email'....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found