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

Cannot work with prisma #113

Open
softmarshmallow opened this issue Mar 8, 2021 · 16 comments
Open

Cannot work with prisma #113

softmarshmallow opened this issue Mar 8, 2021 · 16 comments

Comments

@softmarshmallow
Copy link

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)

prisma/prisma#5392 (comment)

@thebrianbug
Copy link

thebrianbug commented Apr 20, 2021

I am seeing a similar issue. To give more context, what seems to be going on here with this specific error is that prisma is not compatible with the serverless-optimize package.

    "serverless": "^2.37.0",
    "serverless-plugin-optimize": "^4.1.4-rc.1",

Edit - Oh I just realized this is the optimize repo not prisma lol. 🤦

@thebrianbug
Copy link

So here's a list of my prisma versions for help tackling this issue

npx prisma --version
Environment variables loaded from .env
prisma               : 2.20.1
@prisma/client       : 2.20.1
Current platform     : darwin
Query Engine         : query-engine 60ba6551f29b17d7d6ce479e5733c70d9c00860e (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine     : migration-engine-cli 60ba6551f29b17d7d6ce479e5733c70d9c00860e (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 60ba6551f29b17d7d6ce479e5733c70d9c00860e (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary        : prisma-fmt 60ba6551f29b17d7d6ce479e5733c70d9c00860e (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : 60ba6551f29b17d7d6ce479e5733c70d9c00860e
Studio               : 0.365.0

@thebrianbug
Copy link

@goncaloneves Just wondering if you're still maintaining this plugin?

@diogogvhenriques same question^?

I really like how much this little optimize plugin already does for me. I may be able to chip in something to help iron out this specific issue. For me, prisma support is even more important than an optimized build.

I'm wondering if there is a workaround we can use to get unblocked for now? Also, I'm curious what it would take to get a patch fix out there for this as the unexpected token error probably isn't localized to just this one package.

@thebrianbug
Copy link

thebrianbug commented Apr 21, 2021

@softmarshmallow I've managed to get it working with a pretty dirty hacky hotfix. I know it appears to make the issue go away for me. The first commit on that branch has the hacky fix, any more commits are just me trying to actually figure out what's wrong instead of just telling bowerify to ignore the file. But, if this helps anyone else narrow down the scope to some bowerify issue then that's a win.

https://github.com/Album-Health/serverless-plugin-optimize

Super hacky fix: Album-Health@5fa4c2e

EDIT - clarification. Prisma and this plugin aren't working because Bowerify doesn't like this prisma file /Users//services/node_modules/@prisma/client/runtime/index.js

Something in that file is causing Bowerify to hiccup.

@softmarshmallow
Copy link
Author

@softmarshmallow I've managed to get it working with a pretty dirty hacky hotfix. I know it appears to make the issue go away for me. The first commit on that branch has the hacky fix, any more commits are just me trying to actually figure out what's wrong instead of just telling bowerify to ignore the file. But, if this helps anyone else narrow down the scope to some bowerify issue then that's a win.

https://github.com/Album-Health/serverless-plugin-optimize/tree/fix-prisma-issue

Super hacky fix: Album-Health@5fa4c2e

EDIT - clarification. Prisma and this plugin aren't working because Bowerify doesn't like this prisma file /Users//services/node_modules/@prisma/client/runtime/index.js

Something in that file is causing Bowerify to hiccup.

Will try. Thanks !

@softmarshmallow
Copy link
Author

@bmcilw1 Can you publish the package on npm? Dirty but still, this repo is daed. Think we have no option

@softmarshmallow
Copy link
Author

@diogogvhenriques Can you please take a look on this? :) 🙏

@CITGuru
Copy link

CITGuru commented May 27, 2021

@softmarshmallow getting this same issue

@CITGuru
Copy link

CITGuru commented May 27, 2021

@CITGuru
Copy link

CITGuru commented May 27, 2021

This does not seem to work prisma/prisma#7180

@softmarshmallow
Copy link
Author

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",
  // },
};

@thebrianbug
Copy link

thebrianbug commented May 28, 2021

https://www.npmjs.com/package/serverless-plugin-optimize-prisma @softmarshmallow @bmcilw1

I've had to bend this plugin in a couple of hacky ways to make it work. It is not ready for NPM and I'm not willing to make it npm compatible until I'm able to clean up the patches a bit. You are welcome to use this branch if you need to. You can reference it directly in your package.json or fork and reference your own copy.

Link to my fork: https://github.com/Album-Health/serverless-plugin-optimize

Best of luck.

@hoangtrieukd
Copy link

hoangtrieukd commented Sep 30, 2021

image
@bmcilw1 Hi guy, I try use serverless-plugin-optimize-prisma, but it not working. Have any i missing?

------------------ Updated
-- In serverless.yml
I backed to serverless-plugin-optimize and this config, It's working now.

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

@thebrianbug
Copy link

image @bmcilw1 Hi guy, I try use serverless-plugin-optimize-prisma, but it not working. Have any i missing?

------------------ Updated -- In serverless.yml I backed to serverless-plugin-optimize and this config, It's working now.

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

I have no idea what's in the NPM version, I didn't publish it. If those simple switches allowed prisma to work for you, that's great! I might look into swapping back to the main plugin myself if that's the case.

Here's my fork: https://github.com/Album-Health/serverless-plugin-optimize

@nguyenjk
Copy link

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']

@softmarshmallow
Copy link
Author

Also did the magic, but for deployment, when setting binaryTargets = ["native", "rhel-openssl-1.0.x"], it won't work with following errors

Error: EPERM: operation not permitted, unlink '/Users/softmarshmallow/Documents/Apps/grida/base/forms-service/.build/node_modules'
    at Object.unlinkSync (fs.js:1210:3)
    at TypeScriptPlugin.<anonymous> (/Users/softmarshmallow/Documents/Apps/grida/base/forms-service/node_modules/serverless-plugin-typescript/dist/src/index.js:197:24)
    at Generator.next (<anonymous>)
    at /Users/softmarshmallow/Documents/Apps/grida/base/forms-service/node_modules/serverless-plugin-typescript/dist/src/index.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/softmarshmallow/Documents/Apps/grida/base/forms-service/node_modules/serverless-plugin-typescript/dist/src/index.js:4:12)
    at TypeScriptPlugin.copyDependencies (/Users/softmarshmallow/Documents/Apps/grida/base/forms-service/node_modules/serverless-plugin-typescript/dist/src/index.js:191:16)
    at TypeScriptPlugin.<anonymous> (/Users/softmarshmallow/Documents/Apps/grida/base/forms-service/node_modules/serverless-plugin-typescript/dist/src/index.js:60:28)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/softmarshmallow/Documents/Apps/grida/base/forms-service/node_modules/serverless-plugin-typescript/dist/src/index.js:5:58)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

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

5 participants