Serverless-webpack: bug: Cannot read property '1' of null (not #193)

Created on 3 Sep 2021  路  7Comments  路  Source: serverless-heaven/serverless-webpack

This is a (Bug Report / Feature Proposal)

Description

For bug reports:

  • What went wrong?
    When I was doing single deploy, it throws the error Cannot read property '1' of null after successful bundling.
  TypeError: Cannot read property '1' of null
      at getExternalModuleName (/Users/vicary/Documents/[REDACTED]/node_modules/serverless-webpack/lib/compile.js:32:61)
      at isExternalModule (/Users/vicary/Documents/[REDACTED]/node_modules/serverless-webpack/lib/compile.js:45:77)
      at getExternalModules (/Users/vicary/Documents/[REDACTED]/node_modules/serverless-webpack/lib/compile.js:76:9)
      at /Users/vicary/Documents/[REDACTED]/node_modules/serverless-webpack/lib/compile.js:103:24
      at arrayMap (/Users/vicary/Documents/[REDACTED]/node_modules/lodash/lodash.js:653:23)
      at Function.map (/Users/vicary/Documents/[REDACTED]/node_modules/lodash/lodash.js:9622:14)
      at /Users/vicary/Documents/[REDACTED]/node_modules/serverless-webpack/lib/compile.js:101:14
      at tryCatcher (/Users/vicary/Documents/[REDACTED]/node_modules/bluebird/js/release/util.js:16:23)
      at Promise._settlePromiseFromHandler (/Users/vicary/Documents/[REDACTED]/node_modules/bluebird/js/release/promise.js:547:31)
      at Promise._settlePromise (/Users/vicary/Documents/[REDACTED]/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromise0 (/Users/vicary/Documents/[REDACTED]/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/Users/vicary/Documents/[REDACTED]/node_modules/bluebird/js/release/promise.js:729:18)
      at Promise._fulfill (/Users/vicary/Documents/[REDACTED]/node_modules/bluebird/js/release/promise.js:673:18)
      at /Users/vicary/Documents/[REDACTED]/node_modules/bluebird/js/release/nodeback.js:42:21
      at finalCallback (/Users/vicary/Documents/[REDACTED]/node_modules/webpack/lib/Compiler.js:425:32)
      at /Users/vicary/Documents/[REDACTED]/node_modules/webpack/lib/Compiler.js:489:17
      at /Users/vicary/Documents/[REDACTED]/node_modules/webpack/lib/HookWebpackError.js:68:3
      at Hook.eval [as callAsync] (eval at create (/Users/vicary/Documents/[REDACTED]/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
      at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/vicary/Documents/[REDACTED]/node_modules/webpack/node_modules/tapable/lib/Hook.js:18:14)
      at Cache.storeBuildDependencies (/Users/vicary/Documents/[REDACTED]/node_modules/webpack/lib/Cache.js:122:37)
      at /Users/vicary/Documents/[REDACTED]/node_modules/webpack/lib/Compiler.js:485:19
      at Hook.eval [as callAsync] (eval at create (/Users/vicary/Documents/[REDACTED]/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:24:1)
      at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/vicary/Documents/[REDACTED]/node_modules/webpack/node_modules/tapable/lib/Hook.js:18:14)
      at /Users/vicary/Documents/[REDACTED]/node_modules/webpack/lib/Compiler.js:482:23
      at Compiler.emitRecords (/Users/vicary/Documents/[REDACTED]/node_modules/webpack/lib/Compiler.js:874:39)
      at /Users/vicary/Documents/[REDACTED]/node_modules/webpack/lib/Compiler.js:474:11
      at /Users/vicary/Documents/[REDACTED]/node_modules/webpack/lib/Compiler.js:856:14
      at Hook.eval [as callAsync] (eval at create (/Users/vicary/Documents/[REDACTED]/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
      at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/vicary/Documents/[REDACTED]/node_modules/webpack/node_modules/tapable/lib/Hook.js:18:14)
      at /Users/vicary/Documents/[REDACTED]/node_modules/webpack/lib/Compiler.js:853:27
      at /Users/vicary/Documents/[REDACTED]/node_modules/neo-async/async.js:2818:7
      at done (/Users/vicary/Documents/[REDACTED]/node_modules/neo-async/async.js:3522:9)
      at Hook.eval [as callAsync] (eval at create (/Users/vicary/Documents/[REDACTED]/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
      at /Users/vicary/Documents/[REDACTED]/node_modules/webpack/lib/Compiler.js:707:33
      at /Users/vicary/Documents/[REDACTED]/node_modules/graceful-fs/graceful-fs.js:143:16
      at /Users/vicary/Documents/[REDACTED]/node_modules/graceful-fs/graceful-fs.js:61:14
      at FSReqCallback.oncomplete (node:fs:188:23)

Additional Data

  • Serverless-Webpack Version you're using: 5.5.3
  • Webpack version you're using: 5.38.1
  • Serverless Framework Version you're using: 2.57.0
  • Operating System: macOS Big Sur (Apple Silicon)
  • Stack Trace (if available): See above
bug

Most helpful comment

I just hit this as well after upgrading some dependencies. I was able to resolve it by downgrading webpack from 5.52.0 to 5.51.2 (which is very strange to me).

This may also have something to do with NPM bugs. I've noticed an issue with the acorn peer dependency from webpack + eslint + jest: if you're using node 14 + npm 6, npm will fail to find the correct acorn peer dependency for one of webpack's transitive dependencies. The resolution is to uninstall webpack, jest, and eslint, then install webpack, then install jest and eslint. (Doing all 3 in a single command generates a failure.) Webpack maintainers have identified this as a "bug in npm" (without any further information): https://github.com/webpack/webpack/issues/13935

All 7 comments

From further sampling, it sometimes contains "node-commonjs" in the middle.

/^external .*"(.*?)"$/ should fit both cases.

I just hit this as well after upgrading some dependencies. I was able to resolve it by downgrading webpack from 5.52.0 to 5.51.2 (which is very strange to me).

This may also have something to do with NPM bugs. I've noticed an issue with the acorn peer dependency from webpack + eslint + jest: if you're using node 14 + npm 6, npm will fail to find the correct acorn peer dependency for one of webpack's transitive dependencies. The resolution is to uninstall webpack, jest, and eslint, then install webpack, then install jest and eslint. (Doing all 3 in a single command generates a failure.) Webpack maintainers have identified this as a "bug in npm" (without any further information): https://github.com/webpack/webpack/issues/13935

I just hit this as well after upgrading some dependencies. I was able to resolve it by downgrading webpack from 5.52.0 to 5.51.2 (which is very strange to me).

This may also have something to do with NPM bugs. I've noticed an issue with the acorn peer dependency from webpack + eslint + jest: if you're using node 14 + npm 6, npm will fail to find the correct acorn peer dependency for one of webpack's transitive dependencies. The resolution is to uninstall webpack, jest, and eslint, then install webpack, then install jest and eslint. (Doing all 3 in a single command generates a failure.) Webpack maintainers have identified this as a "bug in npm" (without any further information): webpack/webpack#13935

this was also my experience, I removed the node_modules path, installed webpack 5.51.2 and then installed the remaining assets with a npm i -- it works now

I am not sure about the story behind webpack's change on module identifiers.

@j0k3r care to make a comment? I can start a PR if you think the regex fix is good enough.

Looks like it appears here https://github.com/webpack/webpack/pull/14118 (here) with no more information on what is fixed and nothing show up in the changelog.

Anyway please start a PR about it and it you can add a real test to cover that change from webpack, it might be awesome, thanks @vicary !

@j0k3r Wow that was quick, thanks a lot!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bebbi picture bebbi  路  3Comments

serverlesspolska picture serverlesspolska  路  4Comments

bericp1 picture bericp1  路  5Comments

deftomat picture deftomat  路  5Comments

tommedema picture tommedema  路  4Comments