-
-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Loading CodeMirror with webpack (solved) #5484
Comments
I think that's Webpack in this case, and I think that should be reported as a bug there. I'm not really interested in adding workarounds for bugs in other tools to CodeMirror's manual (hopefully, they'll go away soon enough). |
Fair enough 👍 |
Thanks @correnson, works like a charm ! |
Thanks,Solved my problem. |
Working on Rails 6! Thank you 3000! |
@truongnmt how did you import CodeMirror in Rails6? Did you use webpacker? |
Magic thanks @correnson for sharing how to import CodeMirror ! I was about to get mad ! |
Its not allowing me to import from text area and is throwing errors |
Hi all,
I report here an issue that is somehow related to #4838 and to other similar open questions on various forums. I found the problem when using webpack, but I think the issue also comes when simply using
import
. There is no « bug » to fix in the code distribution, but I think something could be added in the installation page of the (awesome) CodeMirror manual, which covers many importation schemes but notimport
explicitly.Here is the story (with suitable webpack & babel configuration):
yarn add codemirror
(or using npm).import CodeMirror from 'codemirror';
works as expected. Good!import 'codemirror/theme/<myTheme>.css';
for your favorite theme. Very Good!import 'codemirror/mode/javascript/javascript.js';
seems to Work (no error in console)...CodeMirror.modes
reveals to be empty!import CodeMirror from 'codemirror/lib/codemirror.js';
then every thing works magically. Yeah!Remark: this simple fix in step #6 above also works with electron + webpack + react + react-hot-loader, contrarily with negative comments found here and there on the web.
Explanation: after deep debugging, it appears that when using
import CodeMirror from 'codemirror'
, the adds-on and modes register themselves in an instance of CodeMirror that is different from the imported one.Actually, all CodeMirror adds-on and modes are using relative paths to their parent
'../lib/codemirror.js'
module. However, it seems that the module cache (whoever is responsible for it) is confused and does not identify'<cm>'
with'<cm>/lib/codemirror.js'
even if'<cm>/package.json'
properly specifies that the main entry is at./lib/codemirror.js'
.The text was updated successfully, but these errors were encountered: