Trying to use prepack on an Angular project built with @angular/cli and I'm getting the following error :
webpackJsonp is not defined
ReferenceError
In order to repro :
# install
yarn global add `@angular/cli`
ng new test-angular-with-prepack --skip-install
cd test-angular-with-prepack
yarn
# build : generate production build with source map
ng build --prod --sm
cd dist
prepack main.*.bundle.js --out main.js
And the error happens here.
_If you don't want to install @angular/cli on your machine, here's a basic project :
test-angular-with-prepack.zip (unzip it, yarn and do what's after the comment #build : generate production build with source map)._
It's because webpackJsonp literally is not defined in the file. Prepack can't know what to expect from external global variables and if they will even exist at runtime. You must provide their definitions.
Add this at the beginning of the file:
__assumeDataProperty(global, "webpackJsonp", __abstract("function"))
Oh is this all it would take to "pepper" the interpreter
I'm going to try and PR this on prepack-webpack-plugin today in the next 20min.
Closing as the question got answered.
I solved this issue by ensuring all other scripts are loaded before main.bundle.js. Check your loader and console out the load order to ensure its correct.
Most helpful comment
It's because
webpackJsonpliterally is not defined in the file. Prepack can't know what to expect from external global variables and if they will even exist at runtime. You must provide their definitions.Add this at the beginning of the file: