I have been using handlebars.js client-side for a while, and I wanted to get into using pre-compiled templates. I followed the general instructions I could find on the web, including installing it on Node.js:
npm install handlebars -g
Next, I go to my Node.js directory and try to compile a simple template:
handlebars test.handlebars -f test.js
And I get an error (command prompt, mind you and i'm sorry):
C:\Users\Administrator\AppData\Roaming\npm\node_modules\handlebars\lib\handlebars.js:1
(function (exports, require, module, __filename, __dirname) { import Handlebar
^^^^^^
SyntaxError: Unexpected reserved word
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (C:\Users\Administrator\AppData\Roaming\npm\node_modules\handlebars\bin\handlebars:105:18)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
I go to this handlebars.js file that errored and sure enough the code definitely doesn't look like javascript:
import Handlebars from "./handlebars.runtime";
// Compiler imports
module AST from "./handlebars/compiler/ast";
import { parser as Parser, parse } from "./handlebars/compiler/base";
// ... etc.
I don't really know what this is, so I don't know what I did wrong or what my problem is.
Looks like lib folder contains not processed ES6-like modules. So probably it was be not processed with es6-module-transpiler. I'm open issue https://github.com/wycats/handlebars.js/issues/642 also exist similar issue https://github.com/wycats/handlebars.js/issues/643 .
I'm workaround this by installing es6-module-transpiler manually process files, and quick fix remain errors (something around with ["default"] exports).
Related
i following an express.js tutorial andd after some code and functionalities with api requests i followed exactly how he changed the code that handles these requests into a seperate js file in another folder just to clean up the code but after i did that this error showed up
i tried changing the file name , i tried removing the node-modules folder and running npm install again and i tried installing the module with the issue
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module '/routes/api/members'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (C:\Users\Get_Rico\Desktop\crashcoursse\index.js:11:25)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
[nodemon] app crashed - waiting for file changes before starting...
i expect nodemon to save the changes and work just fine with no errors just like what happened in the tutorial
It appears the error is probably coming from this line of code and it's telling you that it can't find the '/routes/api/members' module file.
And, this would not be working because you're trying to load a local module without a proper path name. If no path is specified, then it tries to load a global or built-in module. If that module is in the current directory, then you should use the correct path:
const yourModule = './routes/api/members';
Module eth-lightwallet and its' dependencies have some issue with bitcore-lib version guard. I noticed that some of them have version 0.15 and other 0.14. Do you have any solution to this problem? Error that I receive is presented below.
(function (exports, require, module, __filename, __dirname) { var Module;if(!Module)Module=(typeof Module!=="undefined"?Module:null)||{};var moduleOverrides={};for(var key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}var ENVIRONMENT_IS_WEB=typeof window==="object";var ENVIRONMENT_IS_WORKER=typeof importScripts==="function";var ENVIRONMENT_IS_NODE=typeof process==="object"&&typeof require==="function"&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;var ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;if(ENVIRONMENT_IS_NODE){if(!Module["print"])Module["print"]=function print(x){process["stdout"].write(x+"\n")};if(!Module["printErr"])Module["printErr"]=function printErr(x){process["stderr"].write(x+"\n")};var nodeFS=require("fs");var nodePath=require("path");Module["read"]=function read(filename,binary){filename=nodePath["normalize"](filename);var ret=nodeFS["readFileSync"]
Error: More than one instance of bitcore-lib found. Please make sure to require bitcore-lib and check that submodules do not also include their own bitcore-lib dependency.
at Object.bitcore.versionGuard (\GitHub\X\node_modules\eth-lightwallet\node_modules\bitcore-mnemonic\node_modules\bitcore-lib\index.js:12:11)
at Object.<anonymous> (\GitHub\X\node_modules\eth-lightwallet\node_modules\bitcore-mnemonic\node_modules\bitcore-lib\index.js:15:9)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (\GitHub\X\node_modules\eth-lightwallet\node_modules\bitcore-mnemonic\lib\mnemonic.js:3:15)
Process finished with exit code 7`
Full proof solution
In your main file, set _bitcore in global to return undefined on every retrieval of its value. _bitcore is not used for anything other than guarding version in bitcore-lib .
Object.defineProperty(global, '_bitcore', {
get(){
return undefined
},
set(){}
})
The solution provided here worked for me: bitpay/bitcore#1454
Well, this is far from a proper way to solve this issue, but you can
get rid of this error by editing file
~/.nvm/versions/node/v4.8.3/lib/node_modules/bitcore/node_modules/insight-api/node_modules/bitcore-lib/index.js
line 7: bitcore.versionGuard = function(version) { Change it to:
bitcore.versionGuard = function(version) { return;
I did this and so far no problems.
This error causes of version confliction.
I fixed this error by changing the version of
bitcore-lib and bitcore-mnemonic/bitcore-lib by ^0.15.0
(which bitcore-mnemonic/bitcore-lib is ^0.16.0).
Then npm install again.
Failed to load external module babel-core/register
Failed to load external module babel/register
somelocation\gulpfile.babel.js:27
import fs from 'fs';
^^^^^^
SyntaxError: Unexpected reserved word
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:413:25)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Liftoff.handleArguments (\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:116:3)
at Liftoff.<anonymous> (\AppData\Roaming\npm\node_modules\gulp\node_modules\liftoff\index.js:192:16)
at module.exports (\AppData\Roaming\npm\node_modules\gulp\node_modules\liftoff\node_modules\flagged-respawn\index.js:17:3)
I am getting this error while trying to run gulp after npm as described here: deploy-appengine.md. How to fix it?
EDIT: as Luke Bennet points out correctly in a comment to this answer, it was indeed JavaScript - the ES6 "import" syntax. The issue is that this won't work out of the box in Node as yet.
You seem to be using the python module import syntax in NodeJS. You should use the NodeJS module require syntax.
I wanted to create a very minified version of hapi-ninja and came across following problem:
var settings = require('./app/server/config/settings');
var routes = require('./app/server/config/rout');
The first line works as it should an returns my modules. But the second line throws following Exception
AssertionError: path must be a string
at Module.require (module.js:362:3)
at require (module.js:380:17)
at Object.<anonymous> (/home/hknlof/development/mygit/todos/app/server/config/rout.js:8:21)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/hknlof/development/mygit/todos/tryout.js:1:75)
I am running on Node v0.10.25 and hapi-ninja is working fine. When I don't require the rout module it does work. My rout and settings modules look very much the same as in hapi-ninja. I isolated the two require statements in one file. Tried both on their own, still the same result. Can't get my head around this. Tried debugging but the value of the node internal path does never change to the above string. Encoding ist always utf-8.
Thank you vkuchartkin and Tracker1.
So my mistake was that I forgot to require a certain directory in my rout.js
var getController = require(module, '../controller');
was my code. Should have been:
var requireDir = require('require-directory');
var get Controller = requireDir(module, '../controller');
Now I feel a bit stupid
Hello I'm trying to make some Javascript files working on nodeJS everything is well set however here is the error I get :
C:\>node myServer.js
C:\myFunctionsCallTest.js:750
if( (j_lm && (navigator.appName == "Microsoft Internet Explorer")) || navigato
^
ReferenceError: navigator is not defined
at Object.<anonymous> (C:\myFunctionsCallTest.js:750:15)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (C:\myServer.js:1:79)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
C:\>
The files I'm using are :
myServer.js
var my_module = require("./myFunctionsCallTest.js");
console.log("RSA encrypted message :"+ my_module.Encrypt("myKey","myMessage"));
myFunctionsCallTest.js //This file contains some call of prototypes like :
.....................................
RSAKey.prototype.setPublic = RSASetPublic;
RSAKey.prototype._short_encrypt = RSAEncrypt;
RSAKey.prototype.encrypt = RSAEncryptLong;
RSAKey.prototype.encrypt_b64 = RSAEncryptB64;
..............................................
Any idea from where this issue could come?
Thanks.
It looks like you're using Tom Wu's BitInteger and RSA JavaScript library. This library was designed for use in the browser and doesn't work quite right in Node.js.
Luckily, someone has already gone through the work of packaging this library in a Node.js compatible format; it's on GitHub at https://github.com/eschnou/node-bignumber and available via npm as the package "bignumber", and comes with a nice example.