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.

v0.2.6 :: tinypicker isn't defined when using webpack2

See original GitHub issue

I’m using webpack. I’ve added md-color-picker to my package.json, then I’ve added require('md-color-picker'), but I’ve faced with this:

mdColorPicker.min.js:formatted:1 Uncaught ReferenceError: tinycolor is not defined
    at Object.<anonymous> (mdColorPicker.min.js:formatted:1)
    at __webpack_require__ (bootstrap 0e0661051eead7bca74f:54)
    at Object.ELEMENT_NODE (mdColorPicker.min.js:formatted:1)
    at __webpack_require__ (bootstrap 0e0661051eead7bca74f:54)
    at webpackJsonpCallback (bootstrap 0e0661051eead7bca74f:25)
    at mdColorPicker.min.js:formatted:1

Looks md-color-picker itself relies that tinycolor will always be in global scope. But in tinycolor theres a definition:

// Node: Export function
if (typeof module !== "undefined" && module.exports) {
    module.exports = tinycolor;
// AMD/requirejs: Define the module
else if (typeof define === 'function' && define.amd) {
    define(function () {return tinycolor;});
// Browser: Expose to window
else {
    window.tinycolor = tinycolor;

Could you please fix

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

mih-kopylovcommented, Dec 22, 2017

Unfortunately this won’t work as well, (although I haven’t tried it, but it shouldn’t) because it’s not about module import order, it’s about a dependency of md-color-picker module from window.tinycolor variable.

And the request is about excluding this dependency in favour of tinycolor2 module import inside the module

aberenyicommented, Dec 22, 2017

You’re right, sorry I misunderstood your question.

What you could try is to import both packages just before you define the module.

import * as tinycolor from 'tinycolor2'
import * as mdColorPicker from 'md-color-picker'

angular.module('yourApp', [..., 'ngMaterial', 'ngCookies', 'mdColorPicker']);

Have not tried this, but in theory it could work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"require is not defined" Using webpack 2 - Stack Overflow
You're using an incorrect target: target: 'node '. This means that the bundle is intended to be used in a Node.js (server-side) program,...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found