Skip to content
This repository has been archived by the owner on Jun 18, 2022. It is now read-only.

Not working with webpack? #71

Closed
MattFromGer opened this issue Mar 1, 2017 · 6 comments
Closed

Not working with webpack? #71

MattFromGer opened this issue Mar 1, 2017 · 6 comments

Comments

@MattFromGer
Copy link

When trying to pack the module with webpack, I get the following output:

[...]
(function(module, __webpack_exports__, __webpack_require__) {

"use strict";
/*! npm.im/object-fit-images 3.1.3 */
var OFI = 'bfred-it:object-fit-images';
var propRegex = /(object-fit|object-position)\s*:\s*([-\w\s%]+)/g;
[...]

Meaning, webpack cuts off the global variable 'objectFitImages', thus I cannot get it to work.

@fregante
Copy link
Owner

fregante commented Mar 1, 2017

When you use webpack you don't have global variables.

Webpack 1

Use require in your entry file:

var objectFitImages = require('object-fit-images');
objectFitImages('img');

Webpack 2

Use import in your entry file:

import objectFitImages from 'object-fit-images';
objectFitImages('img');

@fregante fregante closed this as completed Mar 1, 2017
@MattFromGer
Copy link
Author

MattFromGer commented Mar 1, 2017

Ah, I see, thank you!

@MattyBalaam
Copy link

I can't get this to work either. I'm using WebPack 2.3.3

Using the code specified I get:

TypeError: objectFitImages is not a function

If I try a console log on that var I get Object {__esModule: true, default: function}

image

I have included what another require looks like

@MattyBalaam
Copy link

MattyBalaam commented Apr 18, 2017

@bfred-it the only way I have been able to get this to work as expected is to use

const objectFitImages = require('object-fit-images').default

@fregante
Copy link
Owner

Thanks for the followup!

It looks like webpack 2 picks up the ES module version even with require. I updated my first comment and I'm reopening this in case anyone else needs it.

@fregante
Copy link
Owner

fregante commented Apr 19, 2017

🎉 If you use object-fit-images version 3.2.0, you can use either require or import without any issues in webpack 2

# run this to get the latest ofi version
npm update object-fit-images --save

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants