I have a working Node application and I'm trying to add Mocha tests, but getting some odd import errors.
This is my file structure:
package.json
index.js
src/
chart.js
test/
test_chart.js
This is what my chart.js file looks like:
global.jQuery = require('jquery');
global.$ = global.jQuery;
require('typeahead');
require('bloodhound');
var bootstrap = require('bootstrap');
var Handlebars = require('handlebars');
var Highcharts = require('highcharts-browserify');
var parse = require('csv-parse');
var moment = require('moment');
var analyseChart = {
doSomething: function() { ... }
};
module.exports = analyseChart;
Currently I import everything from /src into a single index.js file, then bundle it with browserify, which works just fine, no errors in the application.
I have a section in package.json that defines dependencies not available via npm as follows:
"browser": {
"chosen": "./vendor/chosen.jquery.min.js",
"typeahead": "./vendor/typeahead.bundle.js",
"bloodhound": "./vendor/bloodhound.js"
}
Now I want to start writing Mocha tests for the functions in /src.
This is my first stub in test_chart.js:
var chart = require('../src/chart');
chart.doSomething();
But when I run mocha, I get the following error:
/Users/.../js/node_modules/typeahead/node_modules/dom/lib/matches.js:2
var proto = Element.prototype;
^
ReferenceError: Element is not defined
at Object.<anonymous> (/Users/.../js/node_modules/typeahead/node_modules/dom/lib/matches.js:2:13)
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> (/Users/.../js/node_modules/typeahead/node_modules/dom/index.js:4: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> (/Users/.../js/node_modules/typeahead/typeahead.js:3:11)
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> (/Users/.../js/src/chart.js:3:1)
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> (/Users/.../js/test/test_chart.js:3:13)
How can I fix this import error for Mocha?
I think maybe it doesn't like require('typeahead') because it can't see the browser dependency paths that I set in package.json.
Is there a way I can make these files available to Mocha as well as browserify?
Or should I use another testing package altogether?
Related
I have a JavaScript application that is bundled into a client-side application and run in the browser.
An old version of the application used to have a variable assignment like this:
const API_ROOT_URL = `http://${window.location.hostname}:8000/`;
This would presumably get interpolated in the browser.
However, this code now throws a webpack error on webpack 4.42.0:
ReferenceError: window is not defined
at Object.<anonymous> (/usr/src/app/src/client_config.js:4:32)
at Module._compile (/usr/src/app/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (/usr/src/app/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
at Object.<anonymous> (/usr/src/app/webpack.config.js:1:99)
at Module._compile (/usr/src/app/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (/usr/src/app/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
at WEBPACK_OPTIONS (/usr/src/app/node_modules/webpack-cli/bin/utils/convert-argv.js:114:13)
at requireConfig (/usr/src/app/node_modules/webpack-cli/bin/utils/convert-argv.js:116:6)
at /usr/src/app/node_modules/webpack-cli/bin/utils/convert-argv.js:123:17
at Array.forEach (<anonymous>)
at module.exports (/usr/src/app/node_modules/webpack-cli/bin/utils/convert-argv.js:121:15)
at /usr/src/app/node_modules/webpack-cli/bin/cli.js:71:45
at Object.parse (/usr/src/app/node_modules/yargs/yargs.js:567:18)
at /usr/src/app/node_modules/webpack-cli/bin/cli.js:49:8
at Object.<anonymous> (/usr/src/app/node_modules/webpack-cli/bin/cli.js:366:3)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/usr/src/app/node_modules/webpack/bin/webpack.js:156:2)
It seems that the interpolation is happening at the time the bundle is created, when window doesn't exist.
Can I get the intended behavior?
I Have installed the below npm module
https://github.com/feross/simple-peer
by,
#sudo npm install simple-peer -g
But When tried including the module, it is unable to find the module. I received the below error
module.js:340
throw err;
^
Error: Cannot find module 'simple-peer'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/cst/poc/test.js:1:73)
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 Function.Module.runMain (module.js:497:10)
In my sample code I just had
var pee = require('simple-peer');
import plugins from 'gulp-load-plugins';
^^^^^^
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 Liftoff.handleArguments (/usr/local/lib/node_modules/gulp/bin/gulp.js:116:3)
while runnig gulp babel from zurb 6. anyone got idea?
I am trying to get into MeteorJS and learn how it works, however after installing a fresh copy of MeteorJS 1.3 and creating a project, I am always met with the error below.
I've been searching through Google for a while now and I can't come across anyone with the same problem, which is odd because this is a completely fresh installation.
Errors prevented isopacket load:
While loading isopacket `ddp`:
module.js:338:15: Cannot find module './_baseClone'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (C:\Users\Alexander\AppData\Local\.meteor\packages\meteor-tool\1.3.3\mt-os.windows.x86_32\isopackets\ddp\npm\node_modules\meteor\babel-compiler\node_modules\babel-plugin-transform-es2015-modules-commonjs\node_modules\babel-types\node_modules\lodash\clone.js:1:17)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Module.Mp.load (C:\Users\Alexander\AppData\Local\.meteor\packages\meteor-tool\1.3.3\mt-os.windows.x86_32\dev_bundle\lib\node_modules\reify\node\runtime.js:16:23)
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\Alexander\AppData\Local\.meteor\packages\meteor-tool\1.3.3\mt-os.windows.x86_32\isopackets\ddp\npm\node_modules\meteor\babel-compiler\node_modules\babel-plugin-transform-es2015-modules-commonjs\node_modules\babel-types\lib\index.js:314:38)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Module.Mp.load (C:\Users\Alexander\AppData\Local\.meteor\packages\meteor-tool\1.3.3\mt-os.windows.x86_32\dev_bundle\lib\node_modules\reify\node\runtime.js:16:23)
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\Alexander\AppData\Local\.meteor\packages\meteor-tool\1.3.3\mt-os.windows.x86_32\isopackets\ddp\npm\node_modules\meteor\babel-compiler\node_modules\babel-plugin-transform-es2015-modules-commonjs\node_modules\babel-template\lib\index.js:84:43)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Module.Mp.load (C:\Users\Alexander\AppData\Local\.meteor\packages\meteor-tool\1.3.3\mt-os.windows.x86_32\dev_bundle\lib\node_modules\reify\node\runtime.js:16:23)
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\Alexander\AppData\Local\.meteor\packages\meteor-tool\1.3.3\mt-os.windows.x86_32\isopackets\ddp\npm\node_modules\meteor\babel-compiler\node_modules\babel-plugin-transform-es2015-modules-commonjs\lib\index.js:525:46)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Module.Mp.load (C:\Users\Alexander\AppData\Local\.meteor\packages\meteor-tool\1.3.3\mt-os.windows.x86_32\dev_bundle\lib\node_modules\reify\node\runtime.js:16:23)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object._.extend.Npm.require (C:\tools\isobuild\bundler.js:1570:22)
at Object.require (C:\tools\isobuild\bundler.js:1547:11)
at Package (packages/babel-compiler/babel-compiler.js:17:1)
at packages/babel-compiler/babel-compiler.js:356:1
at packages/babel-compiler/babel-compiler.js:356:1
You on Windows 7 or 10 I presume?
I think they broke it with their latest v1.3.3 update today. I am having the exact same issues off brand new installs. Things used to work in v1.3.2 and I am unsure on how to fix this for v1.3.3 yet.
Theoretically though, you can try running it off an older build. Try this.
meteor create myApp --release 1.3.2.4
cd myApp
meteor
It will probably take a really long time to initially create the app, but when it finally finishes it should work. Just don't do "meteor update" on it for now.
If I run flylatex from github, get the following Error on Debian and Ubuntu. Is my nodejs stuff broken or has flylatex a error? At first I run npm install -d in the working directory. My version of nodejs is 0.10.25. The last output is npm info ok Has anyone an idea for fixing the problem?
rennecke#odin ~/flylatex ±master » nodejs app.js
module.js:340
throw err;
^
Error: Cannot find module './src'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/rennecke/flylatex/node_modules/share/index.js:2:18)
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/rennecke/flylatex/app.js:10:13)
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 Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
I had the same problem.
It's a "nodejs and coffee script" problem.
You have to find a way to explain to "nodejs" how to "compile on the fly" coffee script.
I was not able to find the solution but, on my side, the ./node_modules/share/src of coeffeescript was already compile in javascript in the ./node_moudules/share/lib
So I just edit the file :
./node_modules/share/index.js
comment the 2 lines
// require ('coffee-script');
// module.exports = require('./src'):
and add the line
module.exports = require('./lib');
And it's work.
I am still looking for a more "elegant" solution for a "one line" compilation of coffescript.
hope this helps.