Hey guys i got a question, when i wanna use SceneExporter in node.js i got some problem with require it i will show examples:
THREE = require 'three' - here i include module which i instaled to node.js
Export = require './SceneExporter.js' - here is js
ERROR:
THREE.SceneExporter = function () {};
^
ReferenceError: THREE is not defined
How can i use it in node.js ?
Maybe some 1 here did it before.
What's more when i try include three.js from file like here:
THREE = require './three.js'
I get other error:
/home/name/NetBeansProjects/SerwerNode/src/three.js:26561
self._typeface_js = { faces: THREE.FontUtils.faces, loadFace: THREE.FontUtils.
^
ReferenceError: self is not defined
I assume you use this bundle of three.js https://github.com/nulltask/node-three.js
Well, it won't solve your problem, but to the question "Why you can't require SceneExporter ?"
the answer is "because this bundle either is not up-to-date with the original repository or it simply does not include the SceneExporter class"
So, what is best approach to solve your dependency problem ?
I don't have the answer yet, but you should keep an eye on the relevant three.js issue here: https://github.com/mrdoob/three.js/issues/4776
Because node.js does not support window/self, which are Web APIs.
Related
I am trying to call a Javascript file in R. Inside the Java script file has a require function that calls a a Javascript package. When I try to run this in R, I am getting a ReferenceError. I am not so familiar with frontend, but I want to use Javascript to do something for me.
rFile.R
extendShinyjs(script = 'file/jsFile.js')
jsFile.js
var = require('some-module')
Error in R:
Error in : shinyjs: Error parsing the JavaScript file: ReferenceError: require is not defined.
Do you know how I can make this work?
This R Package helped me to convert the npm package to "browserify" it. Thanks for all your help.
https://cran.r-project.org/web/packages/V8/vignettes/npm.html#what_is_v8_(not)
If you will be encountering errors like:
ReferenceError: window is not defined
You need to remove all the lines in bundle.js that uses window. Though I am still not sure of the implications of doing so. I am still working on how to call functions.
This question already has answers here:
Client on Node.js: Uncaught ReferenceError: require is not defined
(11 answers)
Closed 4 years ago.
Edit : Problem solved using webpack
For the needs of an API, I needed to import MD5 and moment. I downloaded the packages using the basic npm install but when I try to import it on my app.js using the code below :
const md5 = require ('./node_modules/md5/md5.js');
const moment = require ('./node_modules/moment/moment.js');
function getTimeStamp () {
return moment.utc ().format ('YYYYMMDDHHmmss');
}
let timestamp = getTimeStamp ();
function generateSignature (devId, method, authKey, timestamp) {
return md5 (`${devId}${method}${apiKey}${timestamp}`);
}
let signature = generateSignature (XXXX, "createsession", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", getTimeStamp ());
I get this message in the console :
Uncaught ReferenceError: require is not defined
I don't know what I'm doing wrong because I used the same method for another program and it worked perfectly...
Thanks in advance
You're probably seeing this error because require() does not exist in the browser/client-side JavaScript.
If you want to use require() in the browser, then you need to use something like require.js
RequireJS is a JavaScript file and module loader. It is optimized for
in-browser use, but it can be used in other JavaScript environments,
like Rhino and Node.
PS: I agree with cptwonton. Please refer to the mentioned post for an in-depth solution with the various options available.
try this:
const md5 = require ("md5");
const moment = require ("moment");
require isn't supported in a browser because Node and ES6 have their different module systems. Are you trying to call require in a browser? In that case I suggest you to setup Babel. But if you use node, then try reistalling nodejs.
I am trying to get global variables working in node.js, but it seems like I don't really understand the concept, even though my understanding matches the documentation.
Minimal example
My main.js file, which is compiled using rollup is:
global.a = 1;
require('./core/test.js');
My core/test.js file is simply:
console.log(a);
This causes the error:
Uncaught ReferenceError: a is not defined
The fully compiled output is:
(function (exports) {
'use strict';
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
console.log(a);
commonjsGlobal.a = 1;
}((this.LaravelElixirBundle = this.LaravelElixirBundle || {})));
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjpudWxsLCJzb3VyY2VzIjpbIkM6L3dhbXAvd3d3L3V1YmMvcmVzb3VyY2VzL2Fzc2V0cy9qcy9jb3JlL3Rlc3QuanMiLCJDOi93YW1wL3d3dy91dWJjL3Jlc291cmNlcy9hc3NldHMvanMvYXBwLmpzIl0sInNvdXJjZXNDb250ZW50IjpbImNvbnNvbGUubG9nKGEpO1xyXG4iLCJnbG9iYWwuYSA9IDE7XHJcbnJlcXVpcmUoJy4vY29yZS90ZXN0LmpzJyk7XHJcbiJdLCJuYW1lcyI6WyJnbG9iYWwiXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUEsT0FBTyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQzs7QUNBZkEsY0FBTSxDQUFDLENBQUMsR0FBRyxDQUFDLENBQUM7OyJ9
It seems that a gets defined after console.log(a);. I'm not 100% sure if this matters in JS but it could be causing the error.
So my question is: what causes this, and what am I doing wrong here?
Possibly relevant information: I'm using Laravel Elixir to compile everything.
Note: Please don't post discussion on whether or not to use global variables in node.js or in general. I know it's usually a bad idea, but I have a very good reason to do it in this case.
Edit: Additional context
What I'm really trying to do is getting Zurb Foundation to work with Laravel Elixir though node.js. I installed foundation-sites through NPM. foundation-sites relies on jquery, which it pulls in itself. However, Foundation doesn't seem to follow the usual conventions of just using something like var jquery = require('jquery'); in its own js file. It actually relies upon a global jQuery variable being available. Therefore I have to ensure that somehow.
My actual file looks like this:
global.jQuery = global.$ = require('jquery');
require('foundation-sites');
So if there are any Foundation/Laravel-specific anwers I would be very happy to hear them as well. Is there something I'm not getting, or did Foundation just not create their package the "right" way?
It looks to me like an issue with your bundler not respecting the order you're doing those two lines in. Your source is clearly:
global.a = 1;
require('./core/test.js');
...but the bundled result is clearly the other way around:
console.log(a);
commonjsGlobal.a = 1;
It seems like it's hoisting the require calls. In general, having require calls that need to be done at a particular point in the execution control flow is not best practice (in fact, when defining modules for ES2015, import is explicitly defined as not being executed in the module's step-by-step control flow).
So if you need to do this, you'll probably want to look at another bundler. But check that it supports order other than dependency resolution order.
You are right that it should work. Here's a working example:
// file1.js
global.a = 'hello';
require('./file2');
// file2.js
console.log(a);
Run node file1.js, and you'll see 'hello' printed to the console.
It looks like you've got some other tool being used (Laravel / Elixir). Use node directly and see what happens.
Alright I solved this in a pretty simple way, by using browserify instead of rollup. Thanks for the other answers pointing me in the right direction. It's not a perfect solution, and I still don't fully understand what the differences are between the two, but it'll do for this project.
The relevant part of my gulpfile:
mix.browserify('app.js','public/js/app.js');
To use browserify with Laravel Elixir, I used
npm install laravel-elixir-browserify-official --save-dev
I solved this for rollup by providing an output.intro that sets up the required variables. In your case this would be:
// rollup.config.js
export default {
// ...
output: {
// ...
intro: `let a = 1;`
}
};
Admittedly this qualifies as a hack, but solves the bundling problem in my case (where switching away from rollup is not an option).
I was trying to deploy a Angular 2 CLI App to a SharePoint 2013 site.
When I embed the app via a Content Editor Webpart, the app seems to work for.
Looking at the console reveals the following exception:
zone.js:158 Uncaught Error: Sys.ParameterCountException: Parameter count mismatch.(…)
Error$create # ScriptResource.axd?d=vGEzwRDnzucQkv59macWaabQYp5RLWFMwrgR1osi9VE8xnWRibgXoL_U0e3xLpsQRNiQ4MJkoONvpt…:237
Error$parameterCount # ScriptResource.axd?d=vGEzwRDnzucQkv59macWaabQYp5RLWFMwrgR1osi9VE8xnWRibgXoL_U0e3xLpsQRNiQ4MJkoONvpt…:413
Function$_validateParameterCount # ScriptResource.axd?d=vGEzwRDnzucQkv59macWaabQYp5RLWFMwrgR1osi9VE8xnWRibgXoL_U0e3xLpsQRNiQ4MJkoONvpt…:118
Function$_validateParams # ScriptResource.axd?d=vGEzwRDnzucQkv59macWaabQYp5RLWFMwrgR1osi9VE8xnWRibgXoL_U0e3xLpsQRNiQ4MJkoONvpt…:70
String$startsWith # ScriptResource.axd?d=vGEzwRDnzucQkv59macWaabQYp5RLWFMwrgR1osi9VE8xnWRibgXoL_U0e3xLpsQRNiQ4MJkoONvpt…:491
startsWith # es6.string.starts-with.js:15Sys$UI$DomEvent # ScriptResource.axd?d=vGEzwRDnzucQkv59macWaabQYp5RLWFMwrgR1osi9VE8xnWRibgXoL_U0e3xLpsQRNiQ4MJkoONvpt…:3986
browserHandler # ScriptResource.axd?d=vGEzwRDnzucQkv59macWaabQYp5RLWFMwrgR1osi9VE8xnWRibgXoL_U0e3xLpsQRNiQ4MJkoONvpt…:4052
ZoneDelegate.invokeTask # zone.js:265Zone.runTask # zone.js:154ZoneTask.invoke # zone.js:335
Where I got so far on my own is, this error is cased by SharePoints AJAX library and the ES6 shims. More accurate the string's startsWith function.
I can't remember having any issues when using angular 2 RC with the systemJS module loader. Even though I used the ES6 shims as well.
I also found out, I used the ES6-Shim directly and the angular cli uses the core-js package from NPM.
Currently I am stuck, so hoping anyone has any input on this matter.
Thanks.
I got a little further. It actually works now. I can't say it works all the way but I got no error so far.
I did remove the following line from the "polyfills.ts":
import 'core-js/es6/string';
This removes the string startsWith function causing the error. Keep in mind this only works if you include the Microsoft Ajax library, so the function is available in general.
If anyone has a better solution I would appreciate it :)
Thanks
I had the same issue in a Sharepoint feature, what worked was adding other and es6 shims before any other js packages are referenced in my master page.
My solution references ended up as:
-node_modules/core-js/client/shim.min.js
-node_modules/es6-shim/es6-shim.min.js
Hope this helps!
I'm trying to use the resemblejs library (http://huddle.github.io/Resemble.js/) to compare two images. However, when I have created a directory and added resemblejs as a dependency, but when I try to run the following:
nodejs test.js, I get the following error
var api = resemble(fileData).onComplete(function(data){
^
ReferenceError: resemble is not defined
I've never used NodeJS before, so it might be something really simple. Any ideas?
You can't get directly node module instance from it. You can check this issue on its repo. node-resemble is an Node port of Resemble.js.
Hope it will be useful for you.