[Solved] Conditional Chaining in NPM package

I was recently trying out a new NPM package and when I tried to deploy to staging the build was either running out of memory (with max_old_space_size =4096 ) or then failing in the minimiser if I increased it to 5120.

Errors prevented bundling:
While minifying app code:

/home/runner/.meteor/packages/zodern_standard-minifier-js/.4.1.1.12dbnq1.dvjo++os+web.browser+web.browser.legacy+web.cordova/plugin.fastMinifier.os/npm/node_modules/meteor/babel-compiler/node_modules/babel-plugin-minify-mangle-names/lib/scope-tracker.js:47:34:
unknown: Cannot read property 'add' of undefined while minifying
packages/modules.js
at ScopeTracker.addReference
(/home/runner/.meteor/packages/zodern_standard-minifier-js/.4.1.1.12dbnq1.dvjo++os+web.browser+web.browser.legacy+web.cordova/plugin.fastMinifier.os/npm/node_modules/meteor/babel-compiler/node_modules/babel-plugin-minify-mangle-names/lib/scope-tracker.js:47:34)
at ReferencedIdentifier
(/home/runner/.meteor/packages/zodern_standard-minifier-js/.4.1.1.12dbnq1.dvjo++os+web.browser+web.browser.legacy+web.cordova/plugin.fastMinifier.os/npm/node_modules/meteor/babel-compiler/node_modules/babel-plugin-minify-mangle-names/lib/index.js:196:26)
at newFn
(/home/runner/.meteor/packages/zodern_standard-minifier-js/.4.1.1.12dbnq1.dvjo++os+web.browser+web.browser.legacy+web.cordova/plugin.fastMinifier.os/npm/node_modules/meteor/babel-compiler/node_modules/@babel/traverse/lib/visitors.js:212:17)
at bfsTraverse

The package I added was a really small and simple one - csvbox but it has conditional chaining.

This should be ok right?

I tried using the recompile options as specified here but that didn’t help. It took a long time though.

So in the end I forked the package, removed the optional chaining and all is good.

We don’t have any special babel config or anything :person_shrugging:

Any ideas?

Interesting, because when bundling Meteor code, the conditional chaining is supported. Does it maybe work when you use the default standard-minifier-js plus recompile option? What I am getting at is, whether this is an issue with the build system in general or if it’s rather related to the zodern:standard-minifier-js package.

1 Like

Do you use a .babelrc config file such as this?

{
  "plugins": [
    "transform-class-properties",
    "@babel/plugin-proposal-optional-chaining",
    ["@babel/plugin-transform-runtime",
      {
        "regenerator": true
      }
    ]
  ],
  "presets": [
    ["@babel/env",
      {
        "targets": [
          "defaults",
          "last 2 versions",
          "not IE 11",
          "node 14"
        ]
      }
    ],
    ["@babel/preset-react"]
  ]
}


1 Like

Thanks for the suggestions :pray: . I tried using the @babel/plugin-proposal-optional-chaining module and no luck. So then I switched to the standard minifier and that worked :partying_face: So now I’ll try remove the plugin and recompile code and see if with just the standard minifier all is well.

Just to update, switching the minifier back to standard is all that was needed. No specific babel plugin, no recompile option. What’s the current recommendation with the minifier? I believe we originally switched to zodern’s because of some issues with the standard one.

You have the option to recompile/transpile NPM Packages according to your meteor app config

https://guide.meteor.com/using-npm-packages.html#recompile