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

import in webpack not working #15

Open
d4l3k opened this issue Aug 27, 2018 · 4 comments
Open

import in webpack not working #15

d4l3k opened this issue Aug 27, 2018 · 4 comments
Labels

Comments

@d4l3k
Copy link

d4l3k commented Aug 27, 2018

When I try to use it via webpack + Polymer 3 + typescript it throws the error:

index.ts:53 ReferenceError: hljs is not defined
    at Object../node_modules/@kuscamara/code-sample/vendor/highlight/highlight.pack.js (highlight.pack.js:formatted:1)
    at __webpack_require__ (bootstrap:767)
    at fn (bootstrap:130)
    at Module../node_modules/@kuscamara/code-sample/code-sample.js (highlight.pack.js:formatted:1)
    at __webpack_require__ (bootstrap:767)
    at fn (bootstrap:130)
    at Module../src/components/index-page/index.ts (indexPage.684e59f8986e2130e02b.chunk.js:76)
    at __webpack_require__ (bootstrap:767)
    at fn (bootstrap:130)

Code:

import '@kuscamara/code-sample/code-sample.js'

Full code https://github.com/d4l3k/feedlight/blob/cc770115d7b85cb3674d74c2610a9773d68b4be3/www/src/components/index-page/index.ts#L3

@d4l3k
Copy link
Author

d4l3k commented Aug 27, 2018

This looks related to highlightjs/highlight.js#712

@d4l3k
Copy link
Author

d4l3k commented Aug 27, 2018

This was fixed by removing import './vendor/highlight/highlight.pack.js'; and then manually importing hljs and adding it to the window.

import hljs from 'highlight.js/lib/highlight'
import javascript from 'highlight.js/lib/languages/javascript'
import xml from 'highlight.js/lib/languages/xml'
hljs.registerLanguage('javascript', javascript)
hljs.registerLanguage('xml', xml)
window['hljs'] = hljs

@kcmr kcmr added the bug label Aug 30, 2018
kcmr pushed a commit that referenced this issue Dec 23, 2019
BREAKING CHANGE: hightlight.js should be imported by the host app
fixes #15
@kcmr
Copy link
Owner

kcmr commented Dec 23, 2019

@d4l3k Thank you for submitting the issue and the fix and sorry for my late response.

highlight won't be imported by code-sample in version 4 that is already available for installation as @kuscamara/code-sample@next.

@kcmr kcmr closed this as completed Dec 23, 2019
@dfsq
Copy link

dfsq commented Jan 4, 2020

@kcmr When trying to use version @next I get warning (which is an error actually, since component also stopes working)

style-gather.js:79 Could not find style data in module named code-sample-theme

@kcmr kcmr reopened this Jan 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants