serverless-bundle icon indicating copy to clipboard operation
serverless-bundle copied to clipboard

serverless-bundle v5: TypeError: Cannot read property '1' of null

Open azizur opened this issue 4 years ago • 11 comments

I just tried upgrading to v5 I am getting Webpack build failure.

My project does not have a webpack config file. When I remove the plugin from the package it eventually builds. Also when I downgrade to 4.4.0, it works as expected.

Not sure where to raise this issue.

I am using sls webpack command for building locally and on CI/CD server.

Serverless: Bundling with Webpack...

 Type Error ----------------------------------------------

  TypeError: Cannot read property '1' of null
      at getExternalModuleName (__PROJECT_PATH__/node_modules/serverless-webpack/lib/compile.js:31:61)
      at isExternalModule (__PROJECT_PATH__/node_modules/serverless-webpack/lib/compile.js:44:77)
      at getExternalModules (__PROJECT_PATH__/node_modules/serverless-webpack/lib/compile.js:75:9)
      at __PROJECT_PATH__/node_modules/serverless-webpack/lib/compile.js:102:24
      at arrayMap (__PROJECT_PATH__/node_modules/lodash/lodash.js:653:23)
      at Function.map (__PROJECT_PATH__/node_modules/lodash/lodash.js:9622:14)
      at __PROJECT_PATH__/node_modules/serverless-webpack/lib/compile.js:100:14
      at finalCallback (__PROJECT_PATH__/node_modules/webpack/lib/Compiler.js:425:32)
      at __PROJECT_PATH__/node_modules/webpack/lib/Compiler.js:489:17
      at __PROJECT_PATH__/node_modules/webpack/lib/HookWebpackError.js:68:3
      at Hook.eval [as callAsync] (eval at create (__PROJECT_PATH__/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
      at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (__PROJECT_PATH__/node_modules/webpack/node_modules/tapable/lib/Hook.js:18:14)
      at Cache.storeBuildDependencies (__PROJECT_PATH__/node_modules/webpack/lib/Cache.js:122:37)
      at __PROJECT_PATH__/node_modules/webpack/lib/Compiler.js:485:19
      at Hook.eval [as callAsync] (eval at create (__PROJECT_PATH__/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
      at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (__PROJECT_PATH__/node_modules/webpack/node_modules/tapable/lib/Hook.js:18:14)
      at __PROJECT_PATH__/node_modules/webpack/lib/Compiler.js:482:23
      at Compiler.emitRecords (__PROJECT_PATH__/node_modules/webpack/lib/Compiler.js:874:39)
      at __PROJECT_PATH__/node_modules/webpack/lib/Compiler.js:474:11
      at __PROJECT_PATH__/node_modules/webpack/lib/Compiler.js:856:14
      at Hook.eval [as callAsync] (eval at create (__PROJECT_PATH__/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
      at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (__PROJECT_PATH__/node_modules/webpack/node_modules/tapable/lib/Hook.js:18:14)
      at __PROJECT_PATH__/node_modules/webpack/lib/Compiler.js:853:27
      at __PROJECT_PATH__/node_modules/neo-async/async.js:2818:7
      at done (__PROJECT_PATH__/node_modules/neo-async/async.js:3522:9)
      at Hook.eval [as callAsync] (eval at create (__PROJECT_PATH__/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
      at __PROJECT_PATH__/node_modules/webpack/lib/Compiler.js:707:33
      at __PROJECT_PATH__/node_modules/graceful-fs/graceful-fs.js:143:16
      at __PROJECT_PATH__/node_modules/graceful-fs/graceful-fs.js:61:14
      at FSReqCallback.oncomplete (fs.js:180:23)
  From previous event:
      at webpackCompile (__PROJECT_PATH__/node_modules/serverless-webpack/lib/compile.js:89:64)
      at BbPromise.map.concurrency.concurrency (__PROJECT_PATH__/node_modules/serverless-webpack/lib/compile.js:108:43)
  From previous event:
      at webpackConcurrentCompile (__PROJECT_PATH__/node_modules/serverless-webpack/lib/compile.js:108:20)
      at ServerlessPlugin.compile (__PROJECT_PATH__/node_modules/serverless-webpack/lib/compile.js:125:12)
  From previous event:
      at Object.webpack:compile:compile [as hook] (__PROJECT_PATH__/node_modules/serverless-webpack/index.js:164:61)
      at PluginManager.invoke (__PROJECT_PATH__/node_modules/serverless/lib/classes/PluginManager.js:579:20)
      at PluginManager.spawn (__PROJECT_PATH__/node_modules/serverless/lib/classes/PluginManager.js:601:16)
      at ServerlessPlugin.<anonymous> (__PROJECT_PATH__/node_modules/serverless-webpack/index.js:156:53)
      at processImmediate (internal/timers.js:464:21)
  From previous event:
      at Object.webpack:webpack [as hook] (__PROJECT_PATH__/node_modules/serverless-webpack/index.js:156:12)
      at PluginManager.invoke (__PROJECT_PATH__/node_modules/serverless/lib/classes/PluginManager.js:579:20)
      at PluginManager.run (__PROJECT_PATH__/node_modules/serverless/lib/classes/PluginManager.js:639:18)
      at async Serverless.run (__PROJECT_PATH__/node_modules/serverless/lib/Serverless.js:452:5)
      at async __PROJECT_PATH__/node_modules/serverless/scripts/serverless.js:795:9

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              14.17.3
     Framework Version:         2.57.0 (local)
     Plugin Version:            5.4.4
     SDK Version:               4.3.0
     Components Version:        3.17.0

azizur avatar Sep 04 '21 10:09 azizur

Hi,

This is a serverless-webpack issue with webpack >= 5.52.0.

Quick fix would be to lock webpack version to 5.51.2.

hrougier avatar Sep 04 '21 22:09 hrougier

Quick fix would be to lock webpack version to 5.51.2.

@hrougier I assume you mean for the serverless-bundle to downgrade webpack version since my project does not have webpack as explicit dependency.

azizur avatar Sep 04 '21 23:09 azizur

If you can confirm that this fixes the issue, please submit a PR and I'll cut a release with it.

jayair avatar Sep 05 '21 02:09 jayair

Hi! Any updates? I am having this exact issue.

afcode123 avatar Sep 06 '21 21:09 afcode123

For me it worked with webpack version 5.51.2

complete package.json

  "dependencies": {
    "aws-sdk": "^2.978.0",
    "serverless-webpack": "",
    "webpack-node-externals": "",
    "webpack": "5.51.2",
    "babel-loader": "",
    "@babel/core": "",
    "babel-plugin-source-map-support": "",
    "@babel/preset-env": ""
  }
}

sbhimani-splunk avatar Sep 07 '21 07:09 sbhimani-splunk

Thanks! Anybody want to submit a PR with this change?

jayair avatar Sep 07 '21 19:09 jayair

i start learning sls+ts+lambda and i have the exact same issue, the fix work

For me it worked with webpack version 5.51.2

complete package.json

  "dependencies": {
    "aws-sdk": "^2.978.0",
    "serverless-webpack": "",
    "webpack-node-externals": "",
    "webpack": "5.51.2",
    "babel-loader": "",
    "@babel/core": "",
    "babel-plugin-source-map-support": "",
    "@babel/preset-env": ""
  }
}

i start learning sls+ts+lambda and i have the exact same issue, the fix work

simontheteemo avatar Sep 07 '21 23:09 simontheteemo

[email protected] has been released a couple hours ago, it should fix this issue with webpack >= 5.52.0

Edit: one would need to submit a PR to bump [email protected] in serverless-bundle, sorry I only use serverless-webpack not serverless-bundle but glad to help!

hrougier avatar Sep 08 '21 10:09 hrougier

Same issue here. As others have mentioned, it seems that [email protected] corrects the issue with webpack 5.52.0.

panchosoft avatar Sep 08 '21 19:09 panchosoft

Published: https://github.com/AnomalyInnovations/serverless-bundle/releases/tag/v5.0.1

jayair avatar Sep 08 '21 21:09 jayair

@panchosoft

Same issue here. As others have mentioned, it seems that [email protected] corrects the issue with webpack 5.52.0.

Indeed. By forcing serverless-webpack in package.json to 5.5.4 and runnining yarn I could finally run sls deploy without errors.

joao-gabriel-gois avatar Sep 11 '21 23:09 joao-gabriel-gois