Skip to content

TypeError: Cannot read property 'type' of undefined #1000

Open

Description

@Novynn

Came across this problem while trying to optimize a script that requires [email protected]. It looks like this line is the culprit:

if (bodyNode.consequent && bodyNode.consequent.body) {

I've fixed it locally by adding && bodyNode.consequent.body.length to the end of the if statement linked because consequent.body is an object not an array in this case ({type: 'BlockStatement', body: {...}}).

Activity

  1. pinuchfab commented on Dec 18, 2019

    @pinuchfab

    Hello, we had the same problems recently while bundling yfiles.
    Would this fix be released in a new version of requirejs from the jquery legacy team?
    Regards
    Fab

  2. anandthakker commented on Jul 15, 2020

    @anandthakker

    I'm seeing this, too, when we optimize a project where one of the included modules is itself a library that was built using r.js (and minified). I can reproduce the error by replacing that module with just this minimal bit of code:

    (function () {
      if (typeof define !== 'undefined') for (;;) {
      }
    })()
    
  3. senthilkumar04 commented on Mar 18, 2021

    @senthilkumar04

    Facing the same type error issue while bundling the packages using r.js
    TypeError: Cannot read property 'type' of undefined

    Is there any updates from the requirejs library for this issue ?

    @Novynn Did you find any work around for this issue ?

  4. prantlf commented on Apr 23, 2023

    @prantlf

    I maintain a fork using a modern JavaScript parser and enhanced source map support as @prantlf/requirejs. I merged #1005 fixing this problem. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions