Im use react_on_rails gem and im try render the component by the server.
When i use components directly from the app it works OK!
import Hello from "../components/Hello"
ReactOnRails.register({
Hello
})
But when i try use a package, the app throws error.
import { Ballon } from "foo-package"
import Hello from "../components/Hello"
ReactOnRails.register({
Ballon,
Hello
})
ERROR in SERVER PRERENDERING
Encountered error: "ReferenceError: document is not defined"
Someone knows why?
window and document are global variables that are only available in a browser environment.
When you are rendering on the server you don't have that environment. You need to safeguard your code and skip invoking any functions on those objects when you are in a node.js environment. For example:
if (typeof document !== 'undefined') {
// Do your document thing here
} else {
console.log("We're on server")
}
I found! The 'foo-package' uses a non isomorphic package. Its breaks the server rendering. The package is react-google-chart.
Related
Trying to grok how to work with js files in Rails 7 using the jsbundling-rails gem and ES modules...
In short, I want to code up functions and have them available in the page.
Here's a simple example. Working with app/javascript/controllers/application.js....
If I paste
alert("HI");
I get an alert in the browser so I know I'm in the right file.
Now, if I paste a simple function
function hello() {
alert("hello");
}
That function does not appear in the compiled js file.
I've tried including the export keyword in front of the function as well...
export function hello() {
alert("hello");
}
I don't know if it's the gem or the way I am writing javascript, but I'm not sure how to proceed.
window.hello = function(){
alert("hello");
}
I am running a React native app with react-i18next and the backend addon. The app works and loads translations perfectly well on Android and Web, but on iOS it fails to load the translations at all.
When i18n is initializing it gives the following error. I am not certain whether the illegal operation error is the cause, but it seems pretty likely.
i18next::backendConnector: loading namespace translation for language en failed, [TypeError: Network request failed]
. . .
Error: EISDIR: illegal operation on a directory, read
at Object.readSync (fs.js:614:3)
at tryReadSync (fs.js:383:20)
at Object.readFileSync (fs.js:420:19)
Is there a configuration somewhere for react-native to let iOS read from the public folder?
My i18n.js:
import * as Localization from 'expo-localization'
import i18n from 'i18next'
import Backend from 'i18next-http-backend'
import { initReactI18next } from 'react-i18next'
i18n
.use(Backend)
.use(initReactI18next)
.init({
compatibilityJSON: 'v3',
debug: true,
fallbackLng: 'en-US',
interpolation: { escapeValue: false },
})
i18n.changeLanguage(Localization.locale)
export default i18n
and my translation file, located at public/locales/en-US/translation.json
{
"outOfStock": "Out of Stock"
}
I suspect expo, like react-native is not hosting the translations so they could be fetched via i18next-http-backend.
So I would suggest you load the translations without i18next-http-backend.
As resources on init: https://www.i18next.com/how-to/add-or-load-translations#add-on-init
or with the help of i18next-resources-to-backend: https://www.i18next.com/how-to/add-or-load-translations#lazy-load-in-memory-translations
For the sake of debugging the javascript-part of a Rails 6 (version 6.0.0.rc1) web application I want to use my custom javascript functions also in the Chrome console (aka. Inspect).
Back when I used just static HTML files to build a website (as opposed to using a web-framework like Rails as of right now) you would simply embed the JS file in the DOM like this
<!-- custom JS -->
<script src="js/custom.js"></script>
and could instantly access and execute all custom functions that were placed in this file.
Background:
The JS file is placed at the correct rails 6 specific directory as provided in this article: How to require custom JS files in Rails 6
Note:
The rails 6 application also uses the JS file already, since the browser shows the console log message.
Here is the full content of the JS file:
// app/javascript/packs/custom.js
console.log("loaded custom.js successfully")
function sayHello () {
console.log("Hello good Sir or Madam!")
}
Expectation: I am expecting to open the browser's (Chrome) console and be able to use the sayHello() function in the console.
However, when I do so, I get an error message in the console stating:
Uncaught ReferenceError: sayHello is not defined
Try something like
sayHello = ()=>{
console.log("Hello good Sir or Madam!");
}
then you can evoke in console:
>sayHello();
I am using zeppelin 0.6.0 (zeppelin-0.6.0-incubating-SNAPSHOT from Hortonworks) and wanted to try out highcharts. So I followed the link to setup my zeppelin. However the zeppelin UI did not have option to add the dependency. So, I made change to the zeppelin configuration file and added the following after copying the jar files - spark-highcharts-0.6.0.jar,
lift-json_2.10-2.6.3.jar and paranamer-2.4.1.jar.
export ZEPPELIN_JAVA_OPTS="-Dspark.executor.memory=8g -Dspark.cores.max=16 --packages com.knockdata:zeppelin-highcharts-0.6.0"
I ran the tutorial notebook in zeppelin and loaded the data.
As per the instructions, I executed java script which ran without any error.
%angular
<script type="text/javascript">
$(function () {
if (typeof Highcharts == "undefined") {
$.getScript("http://code.highcharts.com/highcharts.js")
.done(function( script, textStatus ) {
console.log( "load http://code.highcharts.com/highcharts.js " + textStatus );
})
.fail(function(jqxhr, settings, exception ) {
console.log("load http://code.highcharts.com/highcharts.js " + exception);
});
} else {
console.log("highcharts already loaded");
}
});
</script>
Then I ran the following to plot data which ran fine but there was nothing to plot. Also checked browser console and it did not show any error. Interestingly the java script which i ran earlier did not show any message in browser console too (Expected "highcharts already loaded" message in the console).
%spark
import com.knockdata.zeppelin.highcharts._
import com.knockdata.zeppelin.highcharts.model._
highcharts(bank.series("x" -> "age", "y" -> avg(col("balance")))
.orderBy(col("age"))).plot()
Please let me know what is missing here.
Thanks
This might sound weird but it looks like an issue with Chrome. While experimenting, I started chrome in Incognito mode and ran the highcharts again. This time it showed the chart. Later I cleared the history in Chrome and ran in regular mode.I was able to see the plot. Hope this helps somebody.
I worked with CKEditor on my .Net Mvc4 project. On localhost all works well, but after publishing project to server is not initialising:
"Uncaught TypeError: Cannot set property 'dir' of undefined"
I fixed this by adding code line before editor initialization:
CKEDITOR.basePath = '//some url/ckeditor/'
After that, the ckeditor is working but refusing to open image upload dialog:
error in ckeditor plugins image.js
Uncaught Error: [CKEDITOR.dialog.openDialog] Dialog "image" failed when loading definition.
There is no any changes in my ckeditor folder. The version is: 4.4.5
Any solutions please?
Check the "Network" tab in your browser for HTTP 404 errors. It looks like the file that contains Image Dialog definition is not available. Either it is not present (e.g. has been accidentally removed) or you have some weird url rewrite issues.
Check in your CKEDITOR.basePath plugins folder image plugin is in there, if not then add it and wala working like a charm ! hope it helps !
Issue
You are getting the error from only including the ckeditor.js (or ckeditor4.js since 4.13) file on server, with this error becoming raised when CKE attempts to load other features such as plugins and languages but cannot find these files in the basepath folder. You can confirm this from the network tab in browser devtools, as CKE attempts to load features, then cannot find them.
Option 1: Link to a CDN Bundle
CKE offers 3 primary bundles (basic, standard, full) which offer a choice between features and page load. More info here.
Option 2: Include Necessary Files
Make the extra files available on your server.
Here's a gulp task which bundles everything from the ckeditor node module folder (excluding the sample).
gulp.task("copy-ckeditor", function () {
// Check and copy languages in config.ckEditorLanguages
var isIncluded = function(path) {
var found = false,
lang = path.split('lang')[1];
if (lang) {
for (var i in config.ckEditorLanguages) {
if (lang.indexOf(config.ckEditorLanguages[i]) != -1) {
found = true;
}
}
}
return found;
},
copyFile = function(stream) {
stream.pipe(gulp.dest(config.buildPath.js + "lib/ckeditor"));
};
return gulp.src([
"node_modules/ckeditor/**/*.*",
"!node_modules/ckeditor/samples",
"!node_modules/ckeditor/samples/**/*"
])
.pipe(foreach(function(stream, file){
if (file.path.indexOf("lang") != -1) {
if (isIncluded(file.path)) {
copyFile(stream);
}
} else {
copyFile(stream);
}
return stream;
}));
});
Option 3: Build and Host Your Own Custom Bundle
If you want to use a single file load, you can use the CKE4 Builder allowing you to customise built-in plugins.