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

Not compatible with serverless-webpack #19

Open
orr-levinger opened this issue Dec 14, 2020 · 2 comments
Open

Not compatible with serverless-webpack #19

orr-levinger opened this issue Dec 14, 2020 · 2 comments

Comments

@orr-levinger
Copy link

I am using this plugin for a while now to set env variables.
recently i added the serverless-webpack to reduce my bundle size
i am using typescrypt so my webpack.config looks like this:

/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path');
const slsw = require('serverless-webpack');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');

const isLocal = slsw.lib.webpack.isLocal;

module.exports = {
  mode: isLocal ? 'development' : 'production',
  entry: slsw.lib.entries,
  devtool: 'source-map',
  resolve: {
    extensions: [ '.js', '.jsx', '.json', '.ts', '.tsx' ]
  },
  output: {
    libraryTarget: 'commonjs2',
    path: path.join(__dirname, '.webpack'),
    filename: '[name].js'
  },
  target: 'node',
  module: {
    rules: [
      {
        // Include ts, tsx, js, and jsx files.
        test: /\.(ts|js)x?$/,
        exclude: /node_modules/,
        use: [
          {
            loader: 'cache-loader',
            options: {
              cacheDirectory: path.resolve('.webpackCache')
            }
          },
          'babel-loader'
        ]
      }
    ]
  },
  plugins: [new ForkTsCheckerWebpackPlugin()]
};

i am getting this error from the manifest plugin:

 Error --------------------------------------------------
 
  Error: File "src/functions/auth/pre-sign-up.js" not found. /Users/orrlevinger/projects/BlindChat/blind-chat-backend/src/functions/auth/pre-sign-up.js missing
      at getFunctionPath (/Users/orrlevinger/projects/BlindChat/blind-chat-backend/node_modules/serverless-manifest-plugin/src/index.js:535:11)
      at Object.keys.reduce.urls.apiGateway (/Users/orrlevinger/projects/BlindChat/blind-chat-backend/node_modules/serverless-manifest-plugin/src/index.js:317:30)
      at Array.reduce (<anonymous>)
      at getFormattedData (/Users/orrlevinger/projects/BlindChat/blind-chat-backend/node_modules/serverless-manifest-plugin/src/index.js:213:52)
      at /Users/orrlevinger/projects/BlindChat/blind-chat-backend/node_modules/serverless-manifest-plugin/src/index.js:85:30
      at tryCatcher (/Users/orrlevinger/projects/BlindChat/blind-chat-backend/node_modules/bluebird/js/release/util.js:16:23)
      at Promise._settlePromiseFromHandler (/Users/orrlevinger/projects/BlindChat/blind-chat-backend/node_modules/bluebird/js/release/promise.js:547:31)
      at Promise._settlePromise (/Users/orrlevinger/projects/BlindChat/blind-chat-backend/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromise0 (/Users/orrlevinger/projects/BlindChat/blind-chat-backend/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/Users/orrlevinger/projects/BlindChat/blind-chat-backend/node_modules/bluebird/js/release/promise.js:729:18)
      at _drainQueueStep (/Users/orrlevinger/projects/BlindChat/blind-chat-backend/node_modules/bluebird/js/release/async.js:93:12)
      at _drainQueue (/Users/orrlevinger/projects/BlindChat/blind-chat-backend/node_modules/bluebird/js/release/async.js:86:9)
      at Async._drainQueues (/Users/orrlevinger/projects/BlindChat/blind-chat-backend/node_modules/bluebird/js/release/async.js:102:5)
      at Immediate.Async.drainQueues [as _onImmediate] (/Users/orrlevinger/projects/BlindChat/blind-chat-backend/node_modules/bluebird/js/release/async.js:15:14)
      at processImmediate (internal/timers.js:461:21)
@DavidWells
Copy link
Owner

@cptflammin
Copy link

Hey, getting the same problem here with Typescript, tried this workaround but srcPath does not seem to solve the problem as I feel the individual packing for lambda functions causes troubles:

  1. the plugin looks for .webpack/src/functions/user/ instead of .webpack/confirmuserSignup/src/functions/user/
  2. it might be in addition that at the time when serverless-manifest-plugin looks for .js file the .webpack directory is not present anymore (erased) in the deployment process

using serverless framework template 'aws-nodejs-typescript'

# serverless.yaml
plugins:
  - serverless-offline
  - serverless-appsync-plugin
  - serverless-iam-roles-per-function
  - serverless-webpack
  - serverless-export-env
  - serverless-manifest-plugin
  - serverless-prune-plugin
custom:
  manifest:
      srcPath: .webpack
functions:
  confirmUserSignup:
    handler: src/functions/user/save-user-profile-at-signup.saveUserProfileAtSignup

Webpack config

const path = require('path');
const slsw = require('serverless-webpack');
const nodeExternals = require('webpack-node-externals');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');

module.exports = {
  context: __dirname,
  mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
  entry: slsw.lib.entries,
  devtool: slsw.lib.webpack.isLocal ? 'eval-cheap-module-source-map' : 'source-map',
  resolve: {
    extensions: ['.mjs', '.json', '.ts'],
    symlinks: false,
    cacheWithContext: false,
    plugins: [
      new TsconfigPathsPlugin({
        configFile: './tsconfig.paths.json',
      }),
    ],
  },
  output: {
    libraryTarget: 'commonjs',
    path: path.join(__dirname, '.webpack'),
    filename: '[name].js',
  },
  optimization: {
    concatenateModules: false,
  },
  target: 'node',
  externals: [nodeExternals()],
  module: {
    rules: [
      // all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
      {
        test: /\.(tsx?)$/,
        loader: 'ts-loader',
        exclude: [
          [
            path.resolve(__dirname, 'node_modules'),
            path.resolve(__dirname, '.serverless'),
            path.resolve(__dirname, '.webpack'),
          ],
        ],
        options: {
          transpileOnly: true,
          experimentalWatchApi: true,
        },
      },
    ],
  },
  plugins: [],
};

Output:

.webpack
|- confirmuserSignup
    |- src
         |- functions
             |- user
                  |- save-user-profile-at-signup.js

Error: File "src/functions/user/save-user-profile-at-signup.js" not found. .webpack/src/functions/user/save-user-profile-at-signup.js missing

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

3 participants