Prepack: webpackJsonp is not defined | Angular + cli (webpack)

Created on 4 May 2017  路  5Comments  路  Source: facebook/prepack

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)._

question

Most helpful comment

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"))

All 5 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

obenjiro picture obenjiro  路  4Comments

NTillmann picture NTillmann  路  3Comments

NTillmann picture NTillmann  路  4Comments

MichaelBlume picture MichaelBlume  路  6Comments

phpnode picture phpnode  路  3Comments