danieluhm2004 / serverless-webpack-prisma

When using serverless webpack, you can save up to 50% of package capacity by deleting unnecessary Prisma engine.
https://www.npmjs.com/package/serverless-webpack-prisma
MIT License
33 stars 27 forks source link

--frozen-lockfile failed issue #7

Closed NicholasMKim closed 2 years ago

NicholasMKim commented 2 years ago

Hi team, I'm very struggling to use prisma with webpack and serverless, I'm getting an error like this one. Anyone has a clue? Error: yarn install --non-interactive --frozen-lockfile failed with code 1

This is what my codes looks like package.json

{
  "name": "[name]",
  "version": "1.0.0",
  "description": "",
  "main": "app.ts",
  "scripts": {
    "start": "sls offline",
  },
  "dependencies": {
    "@prisma/client": "^3.9.2",
    "@swifthome/core": "^1.0.19",
    "api-gateway-auth-policy": "^1.0.1",
    "body-parser": "^1.19.2",
    "class-transformer": "^0.3.1",
    "class-validator": "^0.12.2",
    "cors": "^2.8.5",
    "express": "^4.17.1",
    "firebase-admin": "^10.0.2",
    "lodash": "^4.17.21",
    "multer": "^1.4.4",
    "nanoid": "^3.3.1",
    "reflect-metadata": "^0.1.13",
    "routing-controllers": "^0.9.0"
  },
  "devDependencies": {
    "@aws-sdk/client-sesv2": "^3.53.0",
    "@aws-sdk/client-sns": "^3.53.0",
    "@types/body-parser": "^1.19.2",
    "@types/express": "^4.17.13",
    "@types/multer": "^1.4.7",
    "@types/validator": "^13.7.1",
    "aws-sdk": "^2.1082.0",
    "copy-webpack-plugin": "^10.2.4",
    "serverless": "^3.7.1",
    "serverless-http": "^2.7.0",
    "serverless-offline": "^8.4.0",
    "serverless-plugin-typescript": "^2.1.1",
    "serverless-webpack": "^5.6.1",
    "serverless-webpack-prisma": "^1.0.10",
    "ts-loader": "^9.2.7",
    "typescript": "^4.6.2",
    "webpack": "^5.70.0",
    "webpack-node-externals": "^3.0.0"
  }
}

serverless.yml

org: [name]
app: [name]
service: [name]
frameworkVersion: "3"

provider:
  name: aws
  runtime: nodejs14.x
  stage: dev

plugins:
  - serverless-webpack
  # - serverless-plugin-typescript
  - serverless-webpack-prisma
  - serverless-offline

functions: [functions]

package:
  individually: true
  patterns:
    - '!node_modules/.prisma/client/libquery_engine-*'
    - 'node_modules/.prisma/client/libquery_engine-rhel-*'
    - '!node_modules/prisma/libquery_engine-*'
    - '!node_modules/@prisma/engines/**'
custom:
  webpack:
    packager: "yarn"
    includeModules: true
    packagerOptions:
      scripts:
        - npx prisma generate

webpack.config.js

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

module.exports = {
  entry: slsw.lib.entries,
  target: "node",
  mode: "production",
  devtool: "inline-source-map",
  output: {
    libraryTarget: "commonjs",
    path: path.resolve(__dirname, ".webpack"), 
    filename: "[name].js",
  },
  resolve: {
    extensions: [".tsx", ".ts", ".js"],
  },
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: "ts-loader",
        exclude: /node_modules/,
      },
    ],
  },
  externals: {
    _http_common: "commonjs2 _http_common",
    kcors: "kcors",
  },
};

schema.prisma

generator client {
  provider = "prisma-client-js"
  binaryTargets = ["native", "rhel-openssl-1.0.x"]
}
NicholasMKim commented 2 years ago

SOLVED: put private packages into allowList https://github.com/serverless-heaven/serverless-webpack/issues/370#issuecomment-642477672

danieluhm2004 commented 2 years ago

Hello.

As you said, for serverless-webpack, there is a problem when installing private packages.

In addition to the above method of handling exceptions, the following methods can also be used.

webpack:
  packagerOptions:
    noFrozenLockfile: true

I will close the issue. Thank you.