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.

Syntax highlighting not working with webpack v4

See original GitHub issue

BUG REPORT TEMPLATE

I think this issue is affecting vue-codemirror: https://github.com/codemirror/CodeMirror/issues/5484

Vue.js version and component version

VueJs: 2.5.22 vue-codemirror: 4.0.6

Reproduction Link

As far as I can tell, this is a webpack related issue, so it would probably work fine on jsbin or other non-webpack environments.

Steps to reproduce

Create a new project using Vue cli v3 - i.e. using webpack v4. Add vue-codemirror.

What is Expected?

The codemirror instance should load its javascript & theme files, tokenize the input and apply highlighting.

What is actually happening?

It doesn’t tokenize input and therefore doesn’t apply syntax highlighting.

The fix

The fix from here appears to work. If you change this:

import _CodeMirror from 'codemirror'

to this:

import _CodeMirror from 'codemirror/lib/codemirror.js'

in both codemirror.vue & index.js, that seems to fix things. I’m not sure if this is the “correct” way to fix this, so I’ve just made the change locally for now.

If you modify codemirror.vue and/or index.js then you will need to pull these into your project - i.e. don’t use the upstream npm package (from your node_modules) anymore, use your locally modified version.

So, copy the those two files out of your node_modules/vue-codemirror/ folder, into a folder in your project, say src/components/vue-codemirror/, modify them, then change your import line from this:

import VueCodemirror from 'vue-codemirror'
import 'codemirror/lib/codemirror.css'

to this:

import { codemirror } from '@/components/vue-codemirror'
import 'codemirror/lib/codemirror.css'

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:10

github_iconTop GitHub Comments

6reactions
Chieftlcommented, Mar 27, 2019

I found simpler solution, without custom component. Just import “mode” file after codemirror import. For example, for javascript:

import { codemirror } from 'vue-codemirror'
import 'codemirror/mode/javascript/javascript'

But custom component is needed for using inside Electron.

4reactions
ROTGPcommented, Oct 25, 2019

If using Electron-Vue, add 'vue-codemirror' to the array whiteListedModules inside .electron-vue/webpack.renderer.config.js

Read more comments on GitHub >

github_iconTop Results From Across the Web

Highlight.js syntax highlighting not working after webpack build
So I switched back to the minified version, and the syntax highlighting worked. I don't know why that happens though.
Read more >
Javascript syntax highlighting it not working
For me it starts to work when "Enable the new JavaScript language service" (Options->Text Editor->JavaScript/TypeScript->Language Service) is set to unchecked.
Read more >
webpack.config.js losing all syntax highlighting
I am losing syntax highlighting for my webpack.config. If I delete my webpack.config.js then re-create it, it works again.
Read more >
css-loader | webpack - JS.ORG
Starting with version 4.0.0, absolute paths are parsed based on the ... All filtered url() will not be resolved (left in the code...
Read more >
Syntax Highlighting - GitLab Docs
Override syntax highlighting for a file type · If a .gitattributes file does not exist in the root directory of your project, create...
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