I'm not sure if this is a module loader issue, or a transpiling issue, but since upgrading to the latest version (from 0.15.0) I have not been able to get require to work from my dynamically transpiled modules when running in NodeJS. I've also upgraded Babel (5.0.0 to 5.8.21) at the same tiime, so apologies if I'm raising this in the wrong place.
Previously I was able to get code like this to work:
varbunyan=require('bunyan');varlog=bunyan.createLogger({name: 'ct',stream:process.stdout,level:"info",serializers: {websocketMsg:functionwebsocketMsgSerializer(msg){return{eventName:msg.eventName};}}});export{log};This is a module loaded with an es6 import such as:
import { log } from "server-modules/logger/logger.js";
I needed to make a few changes such as installing bable-core and appending .js to my module paths, but the setup should be otherwise the same as my old working code. I setup the es6 module loader like this:
varargv=require('minimist')(process.argv.slice(2));varSystem=require('es6-module-loader').System;System.transpiler='babel';System.babelOptions={blacklist: ['regenerator'],ignore: /node_modules/,sourceMap: true};System.import('./koa-server.js').then(function(index){index.run(__dirname,argv);}).catch(function(err){console.log('top level err',err,err.stack);});`When running the app I get errors like this:
toplevelerr[Error: requireisnotdefined] ReferenceError: requireisnotdefinedatexecute(file:///Users/richard/mysrc/ct/site/server-modules/logger/logger.js!transpiled:9:22)atdoExecute(/Users/richard/mysrc/ct/site/node_modules/es6-module-loader/dist/es6-module-loader-dev.src.js:1190:22)atensureEvaluated(/Users/richard/mysrc/ct/site/node_modules/es6-module-loader/dist/es6-module-loader-dev.src.js:1251:11)atensureEvaluated(/Users/richard/mysrc/ct/site/node_modules/es6-module-loader/dist/es6-module-loader-dev.src.js:1235:15)atensureEvaluated(/Users/richard/mysrc/ct/site/node_modules/es6-module-loader/dist/es6-module-loader-dev.src.js:1235:15)atensureEvaluated(/Users/richard/mysrc/ct/site/node_modules/es6-module-loader/dist/es6-module-loader-dev.src.js:1235:15)atensureEvaluated(/Users/richard/mysrc/ct/site/node_modules/es6-module-loader/dist/es6-module-loader-dev.src.js:1235:15)atensureEvaluated(/Users/richard/mysrc/ct/site/node_modules/es6-module-loader/dist/es6-module-loader-dev.src.js:1235:15)atdoEnsureEvaluated(/Users/richard/mysrc/ct/site/node_modules/es6-module-loader/dist/es6-module-loader-dev.src.js:1214:15)atevaluateLoadedModule(/Users/richard/mysrc/ct/site/node_modules/es6-module-loader/dist/es6-module-loader-dev.src.js:1207:5)
Error evaluatingfile:///Users/richard/mysrc/ct/site/server-modules/logger/logger.js
Error evaluatingfile:///Users/richard/mysrc/ct/site/server-modules/websockets/websocket-client.js
Error evaluatingfile:///Users/richard/mysrc/ct/site/server-modules/websockets/websockets-handler.js
Error evaluatingfile:///Users/richard/mysrc/ct/site/server-modules/server-controller/server-controller.js
Error evaluatingfile:///Users/richard/mysrc/ct/site/server-modules/training-targets/training-targets-server.js
I can see why require would not be defined in a browser environment, but I'm unclear why it is not available in a NodeJS environment. Removing the require from logger.js moves the error along to another file using require. All of this worked ok in 0.15.0.
Any idea what I'm doing wrong here?
Regards,
Richard.
I'm not sure if this is a module loader issue, or a transpiling issue, but since upgrading to the latest version (from 0.15.0) I have not been able to get require to work from my dynamically transpiled modules when running in NodeJS. I've also upgraded Babel (5.0.0 to 5.8.21) at the same tiime, so apologies if I'm raising this in the wrong place.
Previously I was able to get code like this to work:
This is a module loaded with an es6 import such as:
import { log } from "server-modules/logger/logger.js";
I needed to make a few changes such as installing bable-core and appending .js to my module paths, but the setup should be otherwise the same as my old working code. I setup the es6 module loader like this:
When running the app I get errors like this:
I can see why require would not be defined in a browser environment, but I'm unclear why it is not available in a NodeJS environment. Removing the require from logger.js moves the error along to another file using require. All of this worked ok in 0.15.0.
Any idea what I'm doing wrong here?
Regards,
Richard.