Error at production build step with bundle-visualizer: unknown: Cannot read property 'add' of undefined while minifying

I am attempting to upgrade to meteor@2.3.5 from meteor@2.2.3. Development with meteor run works fine. I am getting the following stack trace when running the bundle-visualizer:

$ meteor run --extra-packages bundle-visualizer --production
...
~/.meteor/packages/standard-minifier-js/.2.6.1.1yx4gsm.sv6v++os+web.browser+web.browser.legacy+web.cordova/plugin.minifyStdJS.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 dynamic/node_modules/pdfjs-dist/build/pdf.js
   at ScopeTracker.addReference
...

This seems to be a pretty low-level babel error that resurfaces from time to time as seen in the issue tracker of the babel/minify github repo.

If I remove all import pdfjs from 'pdfjs-dist'; lines (there is only one in this project) the error goes away.

Here is the PR after which the error occurs: Upgrade Meteor to v2.3 by make-github-pseudonymous-again · Pull Request #316 · infoderm/patients · GitHub

Did you try meteor@2.3.4? Just wondering because meteor@2.3.5 is not recommended, yet, and there is a specific change in 2.3.5 related to babel

I did not try 2.3.4 because I was hitting [Resolved] Upgrading to 2.2.1 breaks module compilation. I could try it to see if it produces the same error.

I confirm I am hitting [Resolved] Upgrading to 2.2.1 breaks module compilation with version 2.3.4. I’ll try to remove the code that causes that error and see if the other one shows up.

Just did it by removing all dependent imports. The cumsum parsing error is gone but I still hit the error mentioned in the first post. Here is .meteor/versions:

accounts-base@2.0.1
accounts-password@2.0.0
allow-deny@1.1.0
autoupdate@1.7.0
babel-compiler@7.6.2
babel-runtime@1.5.0
base64@1.0.12
binary-heap@1.0.11
blaze-tools@1.1.1
boilerplate-generator@1.7.1
bundle-visualizer@1.2.3
caching-compiler@1.2.2
caching-html-compiler@1.2.0
callback-hook@1.3.1
check@1.3.1
dburles:factory@1.1.0
ddp@1.4.0
ddp-client@2.5.0
ddp-common@1.4.0
ddp-rate-limiter@1.1.0
ddp-server@2.4.0
diff-sequence@1.1.1
dynamic-import@0.7.1
ecmascript@0.15.2
ecmascript-runtime@0.7.0
ecmascript-runtime-client@0.11.1
ecmascript-runtime-server@0.10.1
ejson@1.1.1
email@2.1.1
es5-shim@4.8.0
fetch@0.1.1
geojson-utils@1.0.10
hot-code-push@1.0.4
hot-module-replacement@0.3.0
html-tools@1.1.1
htmljs@1.1.0
http@1.4.3
id-map@1.1.1
inter-process-messaging@0.1.1
launch-screen@1.3.0
localstorage@1.2.0
logging@1.2.0
meteor@1.9.3
meteor-base@1.5.1
meteortesting:browser-tests@1.3.4
meteortesting:mocha@2.0.1
meteortesting:mocha-core@8.1.2
minifier-css@1.5.4
minifier-js@2.6.1
minimongo@1.7.0
mobile-experience@1.1.0
mobile-status-bar@1.1.0
modern-browsers@0.1.5
modules@0.16.0
modules-runtime@0.12.0
modules-runtime-hot@0.13.0
mongo@1.12.0
mongo-decimal@0.1.2
mongo-dev-server@1.1.0
mongo-id@1.0.8
npm-mongo@3.9.0
ordered-dict@1.1.0
ostrio:cookies@2.7.0
ostrio:files@2.0.1
promise@0.12.0
random@1.2.0
rate-limit@1.0.9
react-fast-refresh@0.1.1
react-meteor-data@2.2.2
reactive-var@1.0.11
reload@1.3.1
retry@1.1.0
routepolicy@1.1.1
service-configuration@1.1.0
sha@1.0.9
shell-server@0.5.0
socket-stream-client@0.4.0
spacebars-compiler@1.2.1
standard-minifier-css@1.7.3
standard-minifier-js@2.6.1
static-html@1.3.0
templating-tools@1.2.0
tracker@1.2.0
typescript@4.3.2
underscore@1.0.10
url@1.3.2
webapp@1.11.1
webapp-hashing@1.1.0

And I have also tried to register pdfjs-dist for recompilation, as suggested here, without success.

Actually, I suspect that in the 2.2.x range 2.2.1 introduced the problem and 2.2.3 fixed it. I know it works with 2.2.3. Let me check that it does not with 2.2.1.

Interesting observation.
Let’s see…
2.2.1 is only Node and npm update.
2.2.2 is only a Node update
2.2.3 is a node and typescript update, but most importantly @meteorjs/babel was updated to fix a bug that was also fixed in the same manner in 2.3.5

OK. I made wrong assumptions. Here is what I can reproduce on the 2.2.x range:

  • 2.2 with typescript (I had just added typescript to the project without running meteor update) or typescript@4.2.2: no error
  • 2.2.1 with typescript@4.2.2: d3-array/cumsum error
  • 2.2.2 with typescript@4.2.2: d3-array/cumsum error
  • 2.2.3 with typescript@4.3.5: no error

I cannot combine for instance 2.2.1 with typescript@4.3.5 since this errors due to incompatible versions.

If I comment out the code dependent on d3-array/cumsum it goes through without errors, so this does not seem related to the problem I am having with pdfjs-dist.

PS: All other explicit version ranges stayed the same (.meteor/packages, .meteor/versions, and package.json).

Still while commenting the d3-array/cumsum dependent code:

  • 2.3 no error
  • 2.3.1 Cannot read property 'add' of undefined while minifying dynamic/node_modules/pdfjs-dist/build/pdf.js
  • 2.3.2 Cannot read property 'add' of undefined while minifying dynamic/node_modules/pdfjs-dist/build/pdf.js
  • 2.3.3 Cannot read property 'add' of undefined while minifying dynamic/node_modules/pdfjs-dist/build/pdf.js
  • 2.3.4 Cannot read property 'add' of undefined while minifying dynamic/node_modules/pdfjs-dist/build/pdf.js
  • 2.3.5 Cannot read property 'add' of undefined while minifying dynamic/node_modules/pdfjs-dist/build/pdf.js

2.2.3 was after the Node upgrade focused on fixing that d3-array error which was an error in Babel which they were constantly fixing and reverting.

It is strange that the error appeared going to 2.3.1. Though there was update to @babel/runtime. This to me suggest that maybe there might an input change to the terser which produces theses issues…

Here is how I proceeded: I ran meteor update --release 2.x.y then meteor run --extra-packages bundle-visualizer --production for each version in increasing order. I ran meteor npm ci when updating from 2.2.x to 2.3 since the NodeJS version changed.

Any other test I could run to help you?

Could you create a small reproduction so that we can debug the same code base?

OK! I’ll ping you when that is done.

1 Like

@storyteller Here it is:

meteor create --release 2.3.5 meteor-2.3.5
cd meteor-2.3.5
meteor npm i
meteor --production # OK
meteor npm i --save pdfjs-dist
echo "import pdfjs from 'pdfjs-dist';" >> client/main.jsx
echo "console.debug(pdfjs);" >> client/main.jsx
meteor --production # NOT OK

Same outcome with TypeScript:

meteor create --release 2.3.5 --typescript meteor-2.3.5-typescript
cd meteor-2.3.5-typescript
meteor npm i
meteor --production # OK
meteor npm i --save pdfjs-dist
echo "import pdfjs from 'pdfjs-dist';" >> client/main.tsx
echo "console.debug(pdfjs);" >> client/main.tsx
meteor --production # NOT OK

@storyteller Same result with METEOR@2.3.6:

meteor create --release 2.3.6 meteor-2.3.6
cd meteor-2.3.6
meteor npm i
meteor --production # OK
meteor npm i --save pdfjs-dist
echo "import pdfjs from 'pdfjs-dist';" >> client/main.jsx
echo "console.debug(pdfjs);" >> client/main.jsx
meteor --production # NOT OK

@storyteller Mmh. Same problem with METEOR@2.2.3, which is the one I am running without problem in my app…

meteor create --release 2.2.3 meteor-2.2.3
cd meteor-2.2.3
meteor npm i
meteor --production # OK
meteor npm i --save pdfjs-dist
echo "import pdfjs from 'pdfjs-dist';" >> client/main.jsx
echo "console.debug(pdfjs);" >> client/main.jsx
meteor --production # NOT OK

@storyteller Any progress?

I’m experiencing this as well when I upgraded from METEOR@2.0