eric eric - 4 months ago 14
Node.js Question

How to configure source lookup paths npm run babel-node similar to browserify's paths?

This is how I include my own modules at the moment:

import AjaxUtils from 'common/util/AjaxUtils";


This is achieved using the "paths" options of browserify.

This is working out perfectly on client side.

Now I'm trying to render the same application on server side with a Express server:

npm run babel-node -- server.js


(The reason I'm using babel-node is that my application is written using ES6/ ECMAScript 2015 syntax.)

The error I'm seeing is:

module.js:338
throw err;
^
Error: Cannot find module 'common/utils/AjaxUtils'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Users/eric/af/frontend_app//components/MyApp.jsx:3:30)
at Module._compile (module.js:460:26)
at normalLoader (/Users/eric/af/frontend_app/node_modules/babel-core/lib/api/register/node.js:199:5)
at Object.require.extensions.(anonymous function) [as .jsx] (/Users/eric/af/frontend_app/node_modules/babel-core/lib/api/register/node.js:216:7)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)


How can configure
npm run
babel-node
to look up modules in specific folders like browserify's "paths" option?

My babel and babel-core version is 5.8.35

Answer

setting environment variable NODE_PATH does it for me

Comments