Enigmatic-Smile / serverless-plugin-optimize

⛔️ DEPRECATED ⛔️ Bundle with Browserify, transpile and minify with Babel automatically to your NodeJS runtime compatible JavaScript

Home Page:https://www.npmjs.com/package/serverless-plugin-optimize

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

make global packages be accessible to the optimized bundle

shierro opened this issue · comments

commented

Hi,

I am using sequelize and it is required that I do
npm install mysql2 --save before the code works.

i tried this config

custom:
  optimize:
    debug: true
    minify: true
    plugins: ['transform-object-rest-spread']
    includePaths: ['.env.example']
    external: ['mysql2']

but i still get this error
You need to install mysql2 package manually
i can see the node_modules folder on the zip file but i suspect it's placed on the wrong folder?

i also tried

require('mysql2');

on my handler but it failed, i think it wasn't able to get the dependencies of mysql2

What could I possibly do to overcome this issue using this plugin?
Will appreciate any help. Thanks!

Also having this issue.

Have you tried #56 (comment) ?

Meaning installing the Mysql2 dependencies?

Yes. In the readme it says that external requires cd external_modules/some-module && npm i --prod

Thank you. I'll check that out.

commented

@selected-pixel-jameson did it work for you? doing

cd node_modules/sequelize && npm i --prod

and adding more on optimize config

  optimize:
    debug: true
    minify: true
    plugins: ['@babel/plugin-proposal-object-rest-spread']
    includePaths: ['.env.example', 'node_modules/mysql2']
    external: ['mysql2']
    externalPaths:
      mysql2: 'node_modules/mysql2'

did not work on my end

I haven't tried yet @shierro

@selected-pixel-jameson @shierro
I had the same issue as you both and solved it by doing the following:

  • Manually install mysql2, so npm install --save mysql2
  • Initiliase the sequelize object with mysql2 module. See require('mysql2') below:
const sequelize = new Sequelize(
    process.env.DB_NAME,
    process.env.DB_USER,
    process.env.DB_PASSWORD,
    {
        dialect: 'mysql',
        // this ensures sequelize uses the mysql2 module you supply
        // and ensures it's included in the optimized bundle because the require is explicit
        dialectModule: require('mysql2'),
        host: process.env.DB_HOST,
        port: process.env.DB_PORT
  }
)