After creating a brand new foundation 6 application with foundation new
, building the application with foundation build
, and loading the application in the web browser, I see the following error on the developer console:
Uncaught TypeError: o(...)(...).foundation is not a function
at Module.<anonymous> (app.js:formatted:4175)
at o (app.js:formatted:11)
at Object.<anonymous> (app.js:formatted:4166)
at o (app.js:formatted:11)
at app.js:formatted:71
at app.js:formatted:72
What gives? It seems like the minifier lost a reference to jquery, because this line seems to correlate to the only line in the generated app.js
that calls the .foundation()
function.
versions on windows. browser is a late chrome.
$ foundation -v; npm -v; node -v; webpack -v
Foundation CLI version 2.2.5
6.4.1
v8.11.1
4.26.1
tldr: use the
Foundation
variable, like this inapp.js
for the curious
here's how i found the answer
find the right source map settings
it took some tweaking, but i found the right source map settings for devtool. change the webpackConfig to
devtool: 'eval'
ingulpfile.babel.js
and build for production with$ gulp build --production
or$ foundation build
. you want the eval setting to be used in production.inspect the source
the browser is still throwing exceptions on the undefined
foundation
, but this time you see who was supposed to define it.marking up the code with comments after the call that brings in
Foundation
from"foundation-sites"
, and building that, then reloading the browser, here's the content ofapp.js
after it's been minified and source mapped:and now the error we get in the console is about that last line:
Uncaught TypeError: jquery__WEBPACK_IMPORTED_MODULE_0___default(...)(...).foundation is not a function
that's crazy, where's
Foundation
?i guess webpack will skip importing Foundation entirely, unless you actually use it in your entry-point code. after guessing that this was the case, i added console statement that printed the
console.info(Foundation)
and bingo. suddenly Foundation Sites imported.