Comments (3)
brace is based on ace which only works in the browser. I doubt that will change, but feel free to file an issue with the ace editor.
from brace.
Woah, hold on!! 😃 I understand Ace is designed to work in the browser. Lots of NPM modules are:
$ node
> require('jquery')
[Function]
> require('three')
{ REVISION: '71', ... }
> require('react')
{ Children: { map: [Function: mapChildren], ...
There's a few issues here:
1. Fundamentally (more below), a module in npm
should be requirable in node land. That's one of the reasons why I and others choose to use this library instead of copying Ace Javascript files into our project.
2. If the project errors at require()
time, that means that simply requiring the project has side effects. Side effects are generally considered Bad™ when they happen when a function runs, and worse when they occur simply from including the presence of code.
3. Strangely, Ace already seems to guard against this. So I'm not yet sure what's causing the window error. If it's something obvious I'll add a bug to the Ace editor as well.
4. In these modern JS times we need libraries to be required in Node for server side rendering (from any library, but namely React). I don't mean that they need to render server side, but they need to be required()
without error. Take this structure for example:
let editor = require('Editor');
let homepage = require('Homepage');
...
render() {
if( page === 'homepage' ) return homepage;
if( page === 'editor' ) return editor;
Even if we're on a page that doesn't render the editor, the editor will still be required. If we try to execute this on the server to render our app to server, it will fail because simply requiring the editor will block load.
5. In these modern JS times, we can test our components in isolated unit tests in NodeJS. Imagine I'm testing the homepage above. I can't, because simply requiring the homepage will require the editor. I can't even load the homepage first to stub out the editor, because I can't require it(!!).
Now I suppose the question centers around point 1. Whose responsibility is it to make the package "work" without side effects in Node? If you're maintaining this project simply by copying over the source files exactly 1:1 from Ace, then it's understandably more tricky because your modified code could get out of sync with the source. If you're making any modifications the code already, then it seems obvious to make minor changes to make it work in node.
FYI, if anyone encounters this issue, one way around this (which isn't great) is to do something like this:
let isClient = typeof window !== "undefined";
let ace = isClient ? require('brace') : function() {};
from brace.
The best friends club:
from brace.
Related Issues (20)
- ace.edit can't find div #javascript-editor inside Angular Material elements
- Lua mode doesn't support the Lua 5.3 floor-division operator '//' HOT 1
- Typo in searchbox.js
- Upgrade ace editor version to latest HOT 7
- Add support to Firefox nunjucks
- Wrong cursur width when typing Asian Characters under Vim Mode HOT 1
- Support for flatbuffers mode
- About AutoCompletion
- Mismatched / incorrect types
- setValue method is emitting the change event twice HOT 2
- Could brace format js code?
- The getname() method cannot get the result of the error prompt in time HOT 1
- Get errors list or invalid state
- How to get Range from Brace and TypeScript? HOT 1
- Hi,how to show line number? HOT 1
- Accessibility: Add role=log attribute to autocomplete popup. #1777
- Question/Accessibility: what is the keyboard combo to get out of of the focus trap?
- Keyboard trap is observed between tool bar section and code block under "Module Twin" tab. HOT 3
- seems not working for chrome mv3 extensions.
- editor: assigning value during initialization of editor
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from brace.