serverless-plugin-optimize
serverless-plugin-optimize copied to clipboard
Cannot work with prisma
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
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. 🤦
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
@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.
@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: https://github.com/Album-Health/serverless-plugin-optimize/commit/5fa4c2ecde4dc4449a989a237ba8e3003e4900ae
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 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 !
@bmcilw1 Can you publish the package on npm? Dirty but still, this repo is daed. Think we have no option
@diogogvhenriques Can you please take a look on this? :) 🙏
@softmarshmallow getting this same issue
https://www.npmjs.com/package/serverless-plugin-optimize-prisma @softmarshmallow @bmcilw1
This does not seem to work https://github.com/prisma/prisma/issues/7180
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",
// },
};
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.
@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']
@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
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']
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)