serverless: Serverless Deploy Error: Path must be a string. Received undefined

This is a (Bug Report / Feature Proposal)

Description

Serverless deploy error: Path must be a string. Received undefined.

Additional Data

  • OS: Mac OS X
  • Serverless version: 1.23.0
  • Webpack version: 1.14.0
  • Serverless webpack version: ^1.0.0-rc.3
  • Typescript version: ^2.2.0

Stack Tract

Serverless: Packaging service...
Serverless: Excluding development dependencies...
path.js:28
    throw new TypeError('Path must be a string. Received ' + inspect(path));
    ^

TypeError: Path must be a string. Received undefined
    at assertPath (path.js:28:11)
    at Object.basename (path.js:1383:5)
    at functionNames.forEach.name (/Users/cmwhited/TransitPros/projects/cloud-api/node_modules/serverless-webpack/lib/cleanup.js:27:28)
    at Array.forEach (<anonymous>)
    at fse.copy (/Users/cmwhited/TransitPros/projects/cloud-api/node_modules/serverless-webpack/lib/cleanup.js:23:31)
    at doneOne (/Users/cmwhited/TransitPros/projects/cloud-api/node_modules/serverless-webpack/node_modules/fs-extra/lib/copy/ncp.js:237:40)
    at /Users/cmwhited/TransitPros/projects/cloud-api/node_modules/serverless-webpack/node_modules/fs-extra/lib/copy/ncp.js:122:11
    at /Users/cmwhited/TransitPros/projects/cloud-api/node_modules/serverless-webpack/node_modules/graceful-fs/polyfills.js:239:18
    at FSReqWrap.oncomplete (fs.js:135:15)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (5 by maintainers)

Most upvoted comments

Thank you. For serverless-webpack@^3.0.0 and webpack@^3.0.0 you should change it as follows:

// webpack.conf.js

const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const slsw = require('serverless-webpack');
const webpack = require('webpack');
const path = require('path');

// You can access the options given to serverles with "slsw.lib.options" and
// the serverless instance with "slsw.lib.serverless". This allows you to dynamically
// build the configuration depending on anything available in serverless (e.g.
// the service definition (slsw.lib.serverless.service.xxxxx)

module.exports = {
    entry: slsw.lib.entries,
    target: 'node',
    module: {
      rules: [
        {
          test: /\.ts(x?)$/,
          use: [
            { loader: 'ts-loader' }
          ]
        },
        {
          test: /\.json$/,
          use: [
            { loader: 'json' }
          ]
        },
        {
          test: /\.sql$/,
          use: [
            { loader: 'raw-loader' }
          ]
        },
        {
          test: /\.(md|jst|def)$/,
          use: [
            { loader: 'ignore-loader' }
          ]
        },
      ]
    },
    resolve: {
        extensions: ['.ts', '.js', '.tsx', '.jsx', '.json', '']
    },
    output: {
        libraryTarget: 'commonjs',
        path: path.join(__dirname, '.webpack'),
        filename: '[name].js',
        comments: false
    },
    plugins: [
        new webpack.optimize.DedupePlugin(),
        new BundleAnalyzerPlugin({
            analyzerMode: 'static',
            reportFilename: 'report.html',
            generateStatsFile: true,
            statsFilename: 'stats.json',
            logLevel: 'info',
            openAnalyzer: false
        })
    ]
};

This entries setting also allows you to use individual packaging together with the plugin, so that each function is optimized and compiled separately. Additionally, it now works with serverless invoke local.

Thanks @cmwhited for reporting 👍 Could you share the serverless.yml you are using so that we can try to reproduce it?