Foundation does not work with create-react-app

I am creating an app with React and create-react-app. I want to use npm foundation sites. I AM:

import React, { Component } from 'react';
import jQuery from 'jquery';
import Foundation from 'foundation-sites';

      

At this point, even without further code, I get an "Uncaught ReferenceError: jQuery not defined" error coming from foundation.js. Usually people fix this with webpack config, but with create-react-app I don't have access to webpack config. I would not like to do eject

. I tried other solutions like here and nothing seems to work. Can Foundation be used with this setup?

+3


source to share


2 answers


Replace the code with the code below and it should work.



import jquery from 'jquery';
window.$ = window.jQuery = jquery;
require('foundation-sites');

      

+2


source


Try assigning jQuery to the window. Preferably, this should be done in the entry point file.



window.jQuery = jQuery;

      

0


source







All Articles