question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't get slick to "import/require" using WebPack, maybe slick doesn't implement a WebPack supported module format?

See original GitHub issue

So I’m doing this:

require('./main.css');
var Jquery = require('jquery');
//var Slick = require('slick');
var React = require('react');

Which works, I get no errors, but if I uncomment the “slick require” I start getting an error:

ReferenceError: require is not defined

I’m new to the whole “js import” thing but am trying out WebPack, and I’m thinking that perhaps slick doesn’t implement a webpack supported “module format”, see: https://github.com/webpack/docs/wiki/shimming-modules

In some cases webpack cannot parse some file, because it has a unsupported module format or isn’t even in a module format.

Could this be true? I think it’s suppose to support “AMD” and “CommonJS” but I may be wrong.

My code is just this code with slick and jquery added.

Oh and here is my config file:

 var webpack = require('webpack');
 var path = require('path');
 var bower_dir = path.join(__dirname, 'bower_components');
 var node_modules_dir = path.join(__dirname, 'node_modules');

 var config = {
   addVendor: function (name, path) {
     this.resolve.alias[name] = path;
     this.module.noParse.push(path);
   },
   context: __dirname,
   entry: {
     app: ['webpack/hot/dev-server', './app/main.js']
   },
   output: {
     publicPath: '/',
     path: path.resolve(__dirname, process.env.NODE_ENV === 'production' ? './dist/' : './build'),
     filename: 'bundle.js'
   },
   resolve: {
     alias: {}
   },
   module: {
     noParse: [],
     loaders: [{
       test: /\.js$/,
       loader: 'jsx-loader',
       exclude: [bower_dir, node_modules_dir]
     }, {
       test: /\.css$/,
       loader: 'style-loader!css-loader'
     }, {
       test: /\.(woff|png)$/,
       loader: 'url-loader?limit=100000'
     }]
   },
   plugins: [
     new webpack.optimize.CommonsChunkPlugin('app', null, false)
   ]
 };

 config.addVendor('react', path.resolve(bower_dir, 'react/react.min.js'));
 config.addVendor('jquery', path.resolve(bower_dir, 'jquery/dist/jquery.min.js'));
 config.addVendor('slick', path.resolve(bower_dir, 'slick.js/slick/slick.min.js'));

 module.exports = config;

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

34reactions
TomOnecommented, Dec 21, 2015

This works for me (without exposing jQuery as global):

import $ from 'jquery';
import 'slick-carousel';

$('.some-element').slick();
16reactions
tnormingtoncommented, Jul 8, 2018

I’m able to import slick js files with webpack like this:

import $ from 'jquery'
import 'slick-carousel'

Then I import the scss files with the @import sass method like this:

$slick-font-path: "~slick-carousel/slick/fonts/"
$slick-loader-path: "~slick-carousel/slick/"
@import "~slick-carousel/slick/slick.scss"
@import "~slick-carousel/slick/slick-theme.scss"

This method lets me override scss variables before I import. I’m using a css-loader, sass-loader, an file-loader with webpack.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack cannot find properly path for slick files - Stack Overflow
I started to using a webpack bundler, and I got a little issue with slick slider. Slick fonts and gif doesn't load properly....
Read more >
Module Methods - webpack
This section covers all methods available in code compiled with webpack. When using webpack to bundle your application, you can pick from a...
Read more >
Common Errors - RequireJS
An error occured when the define() function was called for the module given in the error message. It is an error with the...
Read more >
How to Bundle a Simple Static Site Using Webpack - SitePoint
Add the following to app.js : require('./main.js');. And ...
Read more >
A Guide to Loading External JavaScript in Drupal - Bounteous
Better understand the approaches to add external JavaScript dependencies to your Drupal theme, project, or custom module.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found