Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo's and library isn't working - TypeError: Cannot read property 'configure' of undefined #26

Closed
benhoIIand opened this issue Jun 12, 2014 · 22 comments

Comments

@benhoIIand
Copy link

The demo page is no longer working. The error in the console reads:

TypeError: Cannot read property 'configure' of undefined

image

@pc035860
Copy link
Owner

HI @HollandBen ,

Thanks for reporting. The demo page seems working well for me.
Can you check your "Network" panel, see if http://yandex.st/highlightjs/8.0/highlight.min.js loaded correctly?

@benhoIIand
Copy link
Author

It's getting a response, but with nothing in the body of it. If I go directly to http://yandex.st/highlightjs/8.0/highlight.min.js then I can see the code.

I'm currently using Chrome v35. Just checked it in a few other browsers and it's working fine. Weird.

@alexsomeoddpilot
Copy link

I'm having the same issue while using the library in my code.

The issue is coming from this line which expects hljs to exist as a property on window, but the property is not set.

@alexsomeoddpilot
Copy link

I've determined the real cause is that I wasn't including the original highlightjs library.

Additionally, I'm using Browserify and expected this library to be pulled in automatically.

I'm working on a pull request which will solve for this.

@stickel
Copy link

stickel commented Jul 22, 2015

This error happens when I use the npm modules for both highlight.js and angular-highlightjs along with webpack. Using require('highlight.js'); to load the highlightjs library creates the TypeError: Cannot read property 'configure' of undefined error. When I add a script tag and load highlightjs from the CDN there are no errors and all works well. Is there a way to fix the error using require instead of calling highlightjs from a CDN?

@pc035860
Copy link
Owner

Will work on it this weekend. Thanks for the information!

@pc035860
Copy link
Owner

@stickel I just updated the module pattern to UMD. It's on master branch now. If it works for you, I'll make a release ASAP!

@stickel
Copy link

stickel commented Jul 25, 2015

@pc035860 Close. As it is in master I was getting an error that the module hljs couldn't be found. Updating this conditional in ./build/angular-highlight.js:

(function (root, factory) {
  if (typeof define === "function" && define.amd) {
    define(["angular", "hljs"], factory);
  } else if (typeof module === "object" && module.exports) {
    module.exports = factory(require("angular"), require("highlight.js"));
  } else {
    root.returnExports = factory(root.angular, root.hljs);
  }
}(this, function (angular, hljs) {

to this:

(function (root, factory) {
  if (typeof define === "function" && define.amd) {
    // define(["angular", "hljs"], factory);
    module.exports = factory(require("angular"), require("highlight.js"));
  } else if (typeof module === "object" && module.exports) {
    module.exports = factory(require("angular"), require("highlight.js"));
  } else {
    root.returnExports = factory(root.angular, root.hljs);
  }
}(this, function (angular, hljs) {

Everything started working with webpack. Not sure if/how it'll affect other build tools though.

I posted a few other files for the test app I was using in this gist as well to give you more context.

@pc035860
Copy link
Owner

It seems that webpack's babel-loader will try to resovle modules with every possible pattern (rather than just CommonJS), hence causing

define(["angular", "hljs"], factory);

being looked up in your installed npm modules, where it can't find hljs-named module and caused the error.

I've updated the module name to sync with the CommonJS one. And It should be fine on master now.

@stickel
Copy link

stickel commented Jul 26, 2015

@pc035860 Downloaded and tested the files from master and it's working great. 👍

@pc035860
Copy link
Owner

Just released v0.4.3. Thanks!

@shekharkhedekar
Copy link

@pc035860 I still see this with v0.4.3 (and angular 1.3.17)

TypeError: Cannot read property 'configure' of undefined at Object.ngModule.provider.$get (VM1394 angular-highlightjs.js:47)

@shekharkhedekar
Copy link

Actually - I missed the removal of the highlight.js dependency. Looks like we need to include that separately (using bower for this)?

@pc035860
Copy link
Owner

There's actually no official bower package of highlight.js now (see here).
But there's an official npm package, you can just npm install highlight.js --save for it.

Since you're using webpack, this should work for you.

I'm still wondering whether to add angular and highlight.js dependencies to package.json or not...

@stickel
Copy link

stickel commented Jul 28, 2015

@pc035860 Have you updated the npm package with the newest version? When I try installing 0.4.3 npm can't find that version.

@pc035860
Copy link
Owner

@stickel I forgot to publish the new version to npm... And I'm having some trouble publishing it at home. Will try to publish it tomorrow at work!

@pc035860
Copy link
Owner

v0.4.3 published on npm now. Sorry for the delay!
https://www.npmjs.com/package/angular-highlightjs

@stickel
Copy link

stickel commented Jul 30, 2015

yup

@ghost
Copy link

ghost commented Aug 26, 2015

'bower_components/angular-highlightjs/build/angular-highlightjs.min',
'js/highlight.min',

to

'js/highlight.min',
'bower_components/angular-highlightjs/build/angular-highlightjs.min',

@herrherrmann
Copy link

Last one did the trick for me (loading highlight.js before angular-highlightjs.js) – super-important hint!

@ghost
Copy link

ghost commented Jun 14, 2016

@herrherrmann +1

@thekingofcity
Copy link

@ghost Still helpful. ):

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

No branches or pull requests

7 participants